blob: df00d319be5830a99a8cf996c324ad3ec443dc4d [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"
John Reckf29ed282015-04-07 07:32:03 -070022#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080023#include "android/graphics/GraphicsJNI.h"
24#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080025#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040026
27#include <JNIHelp.h>
28#include <ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080029#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080030#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <gui/Surface.h>
32#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040033#include <jni.h>
34#include <memory>
35#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070036#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080037#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070038#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070039#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080040#include <ui/Rect.h>
41#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042#include <utils/Log.h>
43
Mathias Agopian3866f0d2013-02-11 22:08:48 -080044// ----------------------------------------------------------------------------
45
46namespace android {
47
48static const char* const OutOfResourcesException =
49 "android/view/Surface$OutOfResourcesException";
50
51static struct {
Dan Stoza00101052014-05-02 15:23:40 -070052 jclass clazz;
53 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080054 jfieldID width;
55 jfieldID height;
56 jfieldID refreshRate;
57 jfieldID density;
58 jfieldID xDpi;
59 jfieldID yDpi;
60 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070061 jfieldID appVsyncOffsetNanos;
62 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080063} gPhysicalDisplayInfoClassInfo;
64
Dan Stoza9890e3412014-05-22 16:12:54 -070065static struct {
66 jfieldID bottom;
67 jfieldID left;
68 jfieldID right;
69 jfieldID top;
70} gRectClassInfo;
71
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050072// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
73void DeleteScreenshot(void* addr, void* context) {
74 SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
75 delete ((ScreenshotClient*) context);
76}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080077
Svetoslav1376d602014-03-13 11:17:26 -070078static struct {
79 nsecs_t UNDEFINED_TIME_NANO;
80 jmethodID init;
81} gWindowContentFrameStatsClassInfo;
82
83static struct {
84 nsecs_t UNDEFINED_TIME_NANO;
85 jmethodID init;
86} gWindowAnimationFrameStatsClassInfo;
87
Hangyu Kuang54ac2192016-04-25 13:22:02 -070088static struct {
89 jclass clazz;
90 jmethodID ctor;
91} gHdrCapabilitiesClassInfo;
92
Robert Carr6486d312017-01-09 19:48:29 -080093static struct {
94 jclass clazz;
95 jmethodID builder;
96} gGraphicBufferClassInfo;
97
Mathias Agopian3866f0d2013-02-11 22:08:48 -080098// ----------------------------------------------------------------------------
99
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000100static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500101 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
102 jint windowType, jint ownerUid) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800103 ScopedUtfChars name(env, nameStr);
104 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700105 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800106 sp<SurfaceControl> surface = client->createSurface(
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500107 String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800108 if (surface == NULL) {
109 jniThrowException(env, OutOfResourcesException, NULL);
110 return 0;
111 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500112
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800113 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000114 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800115}
116
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000117static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800118 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800119 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800120}
121
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000122static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800123 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
124 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800125 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800126}
127
Chong Zhang47e36a32016-02-29 16:44:33 -0800128static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
129 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
130 if (ctrl != NULL) {
131 ctrl->disconnect();
132 }
133}
134
Robert Carr6486d312017-01-09 19:48:29 -0800135static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
136 int left = env->GetIntField(rectObj, gRectClassInfo.left);
137 int top = env->GetIntField(rectObj, gRectClassInfo.top);
138 int right = env->GetIntField(rectObj, gRectClassInfo.right);
139 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
140 return Rect(left, top, right, bottom);
141}
142
143static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
144 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
145 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
146 int rotation) {
147 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
148 if (displayToken == NULL) {
149 return NULL;
150 }
151 Rect sourceCrop = rectFromObj(env, sourceCropObj);
152 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800153 minLayer = INT32_MIN;
154 maxLayer = INT32_MAX;
Robert Carr6486d312017-01-09 19:48:29 -0800155 }
156 sp<GraphicBuffer> buffer;
157 status_t res = ScreenshotClient::captureToBuffer(displayToken,
158 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
159 rotation, &buffer);
160 if (res != NO_ERROR) {
161 return NULL;
162 }
163
164 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
165 gGraphicBufferClassInfo.builder,
166 buffer->getWidth(),
167 buffer->getHeight(),
168 buffer->getPixelFormat(),
169 buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100170 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800171}
172
Dan Stoza9890e3412014-05-22 16:12:54 -0700173static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
174 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700175 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
176 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800177 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
178 if (displayToken == NULL) {
179 return NULL;
180 }
181
Robert Carr6486d312017-01-09 19:48:29 -0800182 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700183
Ben Wagner60126ef2015-08-07 12:13:48 -0400184 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500185 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700186 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800187 minLayer = INT32_MIN;
188 maxLayer = INT32_MAX;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500189 }
Riley Andrews1d134062014-08-21 15:47:07 -0700190
191 res = screenshot->update(displayToken, sourceCrop, width, height,
192 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500193 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800194 return NULL;
195 }
196
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400197 SkColorType colorType;
198 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500199 switch (screenshot->getFormat()) {
200 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400201 colorType = kRGBA_8888_SkColorType;
202 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500203 break;
204 }
205 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400206 colorType = kRGBA_8888_SkColorType;
207 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500208 break;
209 }
Romain Guy9505a652016-12-14 09:43:50 -0800210 case PIXEL_FORMAT_RGBA_FP16: {
211 colorType = kRGBA_F16_SkColorType;
212 alphaType = kPremul_SkAlphaType;
213 break;
214 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500215 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400216 colorType = kRGB_565_SkColorType;
217 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500218 break;
219 }
220 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500221 return NULL;
222 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800223 }
Romain Guy26a2b972017-04-17 09:39:51 -0700224
225 sk_sp<SkColorSpace> colorSpace;
226 if (screenshot->getDataSpace() == HAL_DATASPACE_DISPLAY_P3) {
227 colorSpace = SkColorSpace::MakeRGB(
228 SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
229 } else {
230 colorSpace = SkColorSpace::MakeSRGB();
231 }
232
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400233 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
234 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700235 colorType,
236 alphaType,
Romain Guy26a2b972017-04-17 09:39:51 -0700237 colorSpace);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800238
John Reckf29ed282015-04-07 07:32:03 -0700239 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500240 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
241
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400242 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700243 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800244 }
245
sergeyvc1c54062016-10-19 18:47:26 -0700246 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700247 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
248 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400249 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700250 bitmap->setImmutable();
251 return bitmap::createBitmap(env, bitmap,
252 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800253}
254
Dan Stoza9890e3412014-05-22 16:12:54 -0700255static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
256 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
257 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800258 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
259 if (displayToken != NULL) {
260 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
261 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700262 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
263 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
264 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
265 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
266 Rect sourceCrop(left, top, right, bottom);
267
Mathias Agopian0449a402013-03-01 23:01:51 -0800268 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800269 minLayer = INT32_MIN;
270 maxLayer = INT32_MAX;
Mathias Agopian0449a402013-03-01 23:01:51 -0800271 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700272 ScreenshotClient::capture(displayToken,
273 consumer->getIGraphicBufferProducer(), sourceCrop,
Robert Carr7f6e9862017-01-31 09:22:14 -0800274 width, height, minLayer, maxLayer,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800275 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800276 }
277 }
278}
279
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800280static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
281 SurfaceComposerClient::openGlobalTransaction();
282}
283
Robert Carre9953b12016-05-23 20:52:04 -0700284
285static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
286 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800287}
288
289static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
290 SurfaceComposerClient::setAnimationTransaction();
291}
292
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000293static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800294 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
295 status_t err = ctrl->setLayer(zorder);
296 if (err < 0 && err != NO_INIT) {
297 doThrowIAE(env);
298 }
299}
300
Robert Carraf422a82017-04-10 18:34:33 -0700301static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong nativeObject,
302 jobject relativeTo, jint zorder) {
303 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
304 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
305
306 ctrl->setRelativeLayer(handle, zorder);
307}
308
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000309static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800310 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
311 status_t err = ctrl->setPosition(x, y);
312 if (err < 0 && err != NO_INIT) {
313 doThrowIAE(env);
314 }
315}
316
Robert Carr6da3cc02016-06-16 15:17:07 -0700317static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700318 jlong nativeObject) {
319 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700320 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700321 if (err < 0 && err != NO_INIT) {
322 doThrowIAE(env);
323 }
324}
325
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000326static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800327 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
328 status_t err = ctrl->setSize(w, h);
329 if (err < 0 && err != NO_INIT) {
330 doThrowIAE(env);
331 }
332}
333
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000334static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800335 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
336 status_t err = ctrl->setFlags(flags, mask);
337 if (err < 0 && err != NO_INIT) {
338 doThrowIAE(env);
339 }
340}
341
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000342static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800343 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
344 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
345 if (!region) {
346 doThrowIAE(env);
347 return;
348 }
349
350 const SkIRect& b(region->getBounds());
351 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
352 if (region->isComplex()) {
353 SkRegion::Iterator it(*region);
354 while (!it.done()) {
355 const SkIRect& r(it.rect());
356 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
357 it.next();
358 }
359 }
360
361 status_t err = ctrl->setTransparentRegionHint(reg);
362 if (err < 0 && err != NO_INIT) {
363 doThrowIAE(env);
364 }
365}
366
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000367static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800368 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
369 status_t err = ctrl->setAlpha(alpha);
370 if (err < 0 && err != NO_INIT) {
371 doThrowIAE(env);
372 }
373}
374
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000375static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800376 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800377 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr0edf18f2017-02-21 20:01:47 -0800378 status_t err = ctrl->setMatrix(dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800379 if (err < 0 && err != NO_INIT) {
380 doThrowIAE(env);
381 }
382}
383
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000384static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800385 jint l, jint t, jint r, jint b) {
386 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
387 Rect crop(l, t, r, b);
388 status_t err = ctrl->setCrop(crop);
389 if (err < 0 && err != NO_INIT) {
390 doThrowIAE(env);
391 }
392}
393
Pablo Ceballos27982e62016-03-09 10:50:45 -0800394static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
395 jint l, jint t, jint r, jint b) {
396 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
397 Rect crop(l, t, r, b);
398 status_t err = ctrl->setFinalCrop(crop);
399 if (err < 0 && err != NO_INIT) {
400 doThrowIAE(env);
401 }
402}
403
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000404static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800405 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
406 status_t err = ctrl->setLayerStack(layerStack);
407 if (err < 0 && err != NO_INIT) {
408 doThrowIAE(env);
409 }
410}
411
412static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
413 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
414 return javaObjectForIBinder(env, token);
415}
416
417static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
418 jboolean secure) {
419 ScopedUtfChars name(env, nameObj);
420 sp<IBinder> token(SurfaceComposerClient::createDisplay(
421 String8(name.c_str()), bool(secure)));
422 return javaObjectForIBinder(env, token);
423}
424
Jesse Hall6a6bc212013-08-08 12:15:03 -0700425static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
426 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
427 if (token == NULL) return;
428 SurfaceComposerClient::destroyDisplay(token);
429}
430
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800431static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000432 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800433 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
434 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800435 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800436 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800437 if (sur != NULL) {
438 bufferProducer = sur->getIGraphicBufferProducer();
439 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700440 status_t err = SurfaceComposerClient::setDisplaySurface(token,
441 bufferProducer);
442 if (err != NO_ERROR) {
443 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
444 " Surface created with singleBufferMode?");
445 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800446}
447
448static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
449 jobject tokenObj, jint layerStack) {
450 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
451 if (token == NULL) return;
452
453 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
454}
455
456static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
457 jobject tokenObj, jint orientation,
458 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
459 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
460 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
461 if (token == NULL) return;
462 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
463 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
464 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
465}
466
Michael Wright01e840f2014-06-26 16:03:25 -0700467static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
468 jobject tokenObj, jint width, jint height) {
469 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
470 if (token == NULL) return;
471 SurfaceComposerClient::setDisplaySize(token, width, height);
472}
473
Dan Stoza00101052014-05-02 15:23:40 -0700474static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
475 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800476 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700477 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800478
Dan Stoza00101052014-05-02 15:23:40 -0700479 Vector<DisplayInfo> configs;
480 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
481 configs.size() == 0) {
482 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800483 }
484
Dan Stoza00101052014-05-02 15:23:40 -0700485 jobjectArray configArray = env->NewObjectArray(configs.size(),
486 gPhysicalDisplayInfoClassInfo.clazz, NULL);
487
488 for (size_t c = 0; c < configs.size(); ++c) {
489 const DisplayInfo& info = configs[c];
490 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
491 gPhysicalDisplayInfoClassInfo.ctor);
492 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
493 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
494 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
495 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
496 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
497 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
498 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700499 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
500 info.appVsyncOffset);
501 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
502 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700503 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
504 env->DeleteLocalRef(infoObj);
505 }
506
507 return configArray;
508}
509
510static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
511 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
512 if (token == NULL) return -1;
513 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
514}
515
516static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
517 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
518 if (token == NULL) return JNI_FALSE;
519 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
520 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800521}
522
Michael Wright1c9977b2016-07-12 13:30:10 -0700523static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
524 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
525 if (token == NULL) return NULL;
526 Vector<android_color_mode_t> colorModes;
527 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
528 colorModes.isEmpty()) {
529 return NULL;
530 }
531
532 jintArray colorModesArray = env->NewIntArray(colorModes.size());
533 if (colorModesArray == NULL) {
534 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
535 return NULL;
536 }
537 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
538 for (size_t i = 0; i < colorModes.size(); i++) {
539 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
540 }
541 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
542 return colorModesArray;
543}
544
545static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
546 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
547 if (token == NULL) return -1;
548 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
549}
550
551static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
552 jobject tokenObj, jint colorMode) {
553 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
554 if (token == NULL) return JNI_FALSE;
555 status_t err = SurfaceComposerClient::setActiveColorMode(token,
556 static_cast<android_color_mode_t>(colorMode));
557 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
558}
559
Prashant Malanic55929a2014-05-25 01:59:21 -0700560static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800561 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
562 if (token == NULL) return;
563
Prashant Malanic55929a2014-05-25 01:59:21 -0700564 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
565 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800566}
567
Svetoslav1376d602014-03-13 11:17:26 -0700568static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
569 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
570 status_t err = ctrl->clearLayerFrameStats();
571
572 if (err < 0 && err != NO_INIT) {
573 doThrowIAE(env);
574 }
575
576 // The other end is not ready, just report we failed.
577 if (err == NO_INIT) {
578 return JNI_FALSE;
579 }
580
581 return JNI_TRUE;
582}
583
584static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
585 jobject outStats) {
586 FrameStats stats;
587
588 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
589 status_t err = ctrl->getLayerFrameStats(&stats);
590 if (err < 0 && err != NO_INIT) {
591 doThrowIAE(env);
592 }
593
594 // The other end is not ready, fine just return empty stats.
595 if (err == NO_INIT) {
596 return JNI_FALSE;
597 }
598
599 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
600 size_t frameCount = stats.desiredPresentTimesNano.size();
601
602 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
603 if (postedTimesNanoDst == NULL) {
604 return JNI_FALSE;
605 }
606
607 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
608 if (presentedTimesNanoDst == NULL) {
609 return JNI_FALSE;
610 }
611
612 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
613 if (readyTimesNanoDst == NULL) {
614 return JNI_FALSE;
615 }
616
617 nsecs_t postedTimesNanoSrc[frameCount];
618 nsecs_t presentedTimesNanoSrc[frameCount];
619 nsecs_t readyTimesNanoSrc[frameCount];
620
621 for (size_t i = 0; i < frameCount; i++) {
622 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
623 if (postedTimeNano == INT64_MAX) {
624 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
625 }
626 postedTimesNanoSrc[i] = postedTimeNano;
627
628 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
629 if (presentedTimeNano == INT64_MAX) {
630 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
631 }
632 presentedTimesNanoSrc[i] = presentedTimeNano;
633
634 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
635 if (readyTimeNano == INT64_MAX) {
636 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
637 }
638 readyTimesNanoSrc[i] = readyTimeNano;
639 }
640
641 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
642 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
643 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
644
645 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
646 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
647
648 if (env->ExceptionCheck()) {
649 return JNI_FALSE;
650 }
651
652 return JNI_TRUE;
653}
654
655static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
656 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
657
658 if (err < 0 && err != NO_INIT) {
659 doThrowIAE(env);
660 }
661
662 // The other end is not ready, just report we failed.
663 if (err == NO_INIT) {
664 return JNI_FALSE;
665 }
666
667 return JNI_TRUE;
668}
669
670static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
671 FrameStats stats;
672
673 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
674 if (err < 0 && err != NO_INIT) {
675 doThrowIAE(env);
676 }
677
678 // The other end is not ready, fine just return empty stats.
679 if (err == NO_INIT) {
680 return JNI_FALSE;
681 }
682
683 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
684 size_t frameCount = stats.desiredPresentTimesNano.size();
685
686 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
687 if (presentedTimesNanoDst == NULL) {
688 return JNI_FALSE;
689 }
690
691 nsecs_t presentedTimesNanoSrc[frameCount];
692
693 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700694 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700695 if (presentedTimeNano == INT64_MAX) {
696 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
697 }
698 presentedTimesNanoSrc[i] = presentedTimeNano;
699 }
700
701 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
702
703 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
704 presentedTimesNanoDst);
705
706 if (env->ExceptionCheck()) {
707 return JNI_FALSE;
708 }
709
710 return JNI_TRUE;
711}
712
Rob Carr64e516f2015-10-29 00:20:45 +0000713static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
714 jobject handleObject, jlong frameNumber) {
715 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
716 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
717
718 ctrl->deferTransactionUntil(handle, frameNumber);
719}
720
Robert Carrd5c7dd62017-03-08 10:39:30 -0800721static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong nativeObject,
722 jlong surfaceObject, jlong frameNumber) {
723 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
724 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
725
726 ctrl->deferTransactionUntil(barrier, frameNumber);
727}
728
729static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong nativeObject,
730 jobject newParentObject) {
731 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
732 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
733
734 ctrl->reparentChildren(handle);
735}
736
737static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong nativeObject) {
738 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
739 ctrl->detachChildren();
740}
741
Robert Carr1ca6a332016-04-11 18:00:43 -0700742static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
743 jint scalingMode) {
744 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
745
746 ctrl->setOverrideScalingMode(scalingMode);
747}
748
Rob Carr64e516f2015-10-29 00:20:45 +0000749static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
750 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
751
752 return javaObjectForIBinder(env, ctrl->getHandle());
753}
754
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700755static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
756 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
757 if (token == NULL) return NULL;
758
759 HdrCapabilities capabilities;
760 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
761
762 const auto& types = capabilities.getSupportedHdrTypes();
763 auto typesArray = env->NewIntArray(types.size());
764 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
765
Michael Wright9ff94c02016-03-30 18:05:40 -0700766 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700767 typesArray, capabilities.getDesiredMaxLuminance(),
768 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
769}
770
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800771// ----------------------------------------------------------------------------
772
Daniel Micay76f6a862015-09-19 17:31:01 -0400773static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500774 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800775 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000776 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800777 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000778 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800779 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800780 {"nativeDisconnect", "(J)V",
781 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700782 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800783 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700784 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800785 (void*)nativeScreenshot },
786 {"nativeOpenTransaction", "()V",
787 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700788 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800789 (void*)nativeCloseTransaction },
790 {"nativeSetAnimationTransaction", "()V",
791 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000792 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800793 (void*)nativeSetLayer },
Robert Carraf422a82017-04-10 18:34:33 -0700794 {"nativeSetRelativeLayer", "(JLandroid/os/IBinder;I)V",
795 (void*)nativeSetRelativeLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000796 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800797 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700798 {"nativeSetGeometryAppliesWithResize", "(J)V",
799 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000800 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800801 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000802 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800803 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000804 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800805 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000806 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800807 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000808 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800809 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000810 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800811 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800812 {"nativeSetFinalCrop", "(JIIII)V",
813 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000814 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800815 (void*)nativeSetLayerStack },
816 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
817 (void*)nativeGetBuiltInDisplay },
818 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
819 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700820 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
821 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000822 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800823 (void*)nativeSetDisplaySurface },
824 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
825 (void*)nativeSetDisplayLayerStack },
826 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
827 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700828 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
829 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700830 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
831 (void*)nativeGetDisplayConfigs },
832 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
833 (void*)nativeGetActiveConfig },
834 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
835 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700836 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
837 (void*)nativeGetDisplayColorModes},
838 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
839 (void*)nativeGetActiveColorMode},
840 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
841 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700842 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
843 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700844 {"nativeClearContentFrameStats", "(J)Z",
845 (void*)nativeClearContentFrameStats },
846 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
847 (void*)nativeGetContentFrameStats },
848 {"nativeClearAnimationFrameStats", "()Z",
849 (void*)nativeClearAnimationFrameStats },
850 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
851 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700852 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
853 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000854 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
855 (void*)nativeDeferTransactionUntil },
Robert Carrd5c7dd62017-03-08 10:39:30 -0800856 {"nativeDeferTransactionUntilSurface", "(JJJ)V",
857 (void*)nativeDeferTransactionUntilSurface },
858 {"nativeReparentChildren", "(JLandroid/os/IBinder;)V",
859 (void*)nativeReparentChildren } ,
860 {"nativeSeverChildren", "(J)V",
861 (void*)nativeSeverChildren } ,
Robert Carr1ca6a332016-04-11 18:00:43 -0700862 {"nativeSetOverrideScalingMode", "(JI)V",
863 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000864 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700865 (void*)nativeGetHandle },
Robert Carr6486d312017-01-09 19:48:29 -0800866 {"nativeScreenshotToBuffer",
867 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
868 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800869};
870
871int register_android_view_SurfaceControl(JNIEnv* env)
872{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800873 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800874 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
875
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800876 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
877 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
878 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
879 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
880 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
881 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
882 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
883 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
884 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
885 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
886 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
887 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
888 clazz, "appVsyncOffsetNanos", "J");
889 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
890 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700891
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800892 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
893 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
894 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
895 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
896 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700897
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800898 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
899 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
900 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700901 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
902
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800903 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
904 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
905 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700906 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
907
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800908 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
909 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
910 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700911 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
912
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700913 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
914 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
915 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
916 "([IFFF)V");
917
Robert Carr6486d312017-01-09 19:48:29 -0800918 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
919 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
920 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
921 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
922
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800923 return err;
924}
925
926};