blob: d7d8dd916d00d7617476e735139ee5bb8e35372e [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
Tom Cherry8ed74bb2017-07-10 14:31:18 -070027#include <android-base/chrono_utils.h>
Steven Moreland2279b252017-07-19 09:50:45 -070028#include <nativehelper/JNIHelp.h>
29#include <nativehelper/ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080030#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <gui/Surface.h>
33#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040034#include <jni.h>
35#include <memory>
36#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070037#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070039#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070040#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080041#include <ui/Rect.h>
42#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080043#include <utils/Log.h>
44
Mathias Agopian3866f0d2013-02-11 22:08:48 -080045// ----------------------------------------------------------------------------
46
47namespace android {
48
49static const char* const OutOfResourcesException =
50 "android/view/Surface$OutOfResourcesException";
51
52static struct {
Dan Stoza00101052014-05-02 15:23:40 -070053 jclass clazz;
54 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080055 jfieldID width;
56 jfieldID height;
57 jfieldID refreshRate;
58 jfieldID density;
59 jfieldID xDpi;
60 jfieldID yDpi;
61 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070062 jfieldID appVsyncOffsetNanos;
63 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080064} gPhysicalDisplayInfoClassInfo;
65
Dan Stoza9890e3412014-05-22 16:12:54 -070066static struct {
67 jfieldID bottom;
68 jfieldID left;
69 jfieldID right;
70 jfieldID top;
71} gRectClassInfo;
72
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050073// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
74void DeleteScreenshot(void* addr, void* context) {
75 SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
76 delete ((ScreenshotClient*) context);
77}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080078
Svetoslav1376d602014-03-13 11:17:26 -070079static struct {
80 nsecs_t UNDEFINED_TIME_NANO;
81 jmethodID init;
82} gWindowContentFrameStatsClassInfo;
83
84static struct {
85 nsecs_t UNDEFINED_TIME_NANO;
86 jmethodID init;
87} gWindowAnimationFrameStatsClassInfo;
88
Hangyu Kuang54ac2192016-04-25 13:22:02 -070089static struct {
90 jclass clazz;
91 jmethodID ctor;
92} gHdrCapabilitiesClassInfo;
93
Robert Carr6486d312017-01-09 19:48:29 -080094static struct {
95 jclass clazz;
96 jmethodID builder;
97} gGraphicBufferClassInfo;
98
Mathias Agopian3866f0d2013-02-11 22:08:48 -080099// ----------------------------------------------------------------------------
100
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000101static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500102 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
103 jint windowType, jint ownerUid) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800104 ScopedUtfChars name(env, nameStr);
105 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700106 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800107 sp<SurfaceControl> surface = client->createSurface(
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500108 String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800109 if (surface == NULL) {
110 jniThrowException(env, OutOfResourcesException, NULL);
111 return 0;
112 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500113
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800114 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000115 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800116}
117
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000118static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800119 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800120 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800121}
122
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000123static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800124 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
125 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800126 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800127}
128
Chong Zhang47e36a32016-02-29 16:44:33 -0800129static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
130 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
131 if (ctrl != NULL) {
132 ctrl->disconnect();
133 }
134}
135
Robert Carr6486d312017-01-09 19:48:29 -0800136static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
137 int left = env->GetIntField(rectObj, gRectClassInfo.left);
138 int top = env->GetIntField(rectObj, gRectClassInfo.top);
139 int right = env->GetIntField(rectObj, gRectClassInfo.right);
140 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
141 return Rect(left, top, right, bottom);
142}
143
144static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
145 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
146 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
147 int rotation) {
148 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
149 if (displayToken == NULL) {
150 return NULL;
151 }
152 Rect sourceCrop = rectFromObj(env, sourceCropObj);
153 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800154 minLayer = INT32_MIN;
155 maxLayer = INT32_MAX;
Robert Carr6486d312017-01-09 19:48:29 -0800156 }
157 sp<GraphicBuffer> buffer;
158 status_t res = ScreenshotClient::captureToBuffer(displayToken,
159 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
160 rotation, &buffer);
161 if (res != NO_ERROR) {
162 return NULL;
163 }
164
165 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
166 gGraphicBufferClassInfo.builder,
167 buffer->getWidth(),
168 buffer->getHeight(),
169 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700170 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100171 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800172}
173
Dan Stoza9890e3412014-05-22 16:12:54 -0700174static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
175 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700176 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
177 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800178 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
179 if (displayToken == NULL) {
180 return NULL;
181 }
182
Robert Carr6486d312017-01-09 19:48:29 -0800183 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700184
Ben Wagner60126ef2015-08-07 12:13:48 -0400185 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500186 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700187 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800188 minLayer = INT32_MIN;
189 maxLayer = INT32_MAX;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500190 }
Riley Andrews1d134062014-08-21 15:47:07 -0700191
192 res = screenshot->update(displayToken, sourceCrop, width, height,
193 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500194 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800195 return NULL;
196 }
197
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400198 SkColorType colorType;
199 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500200 switch (screenshot->getFormat()) {
201 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400202 colorType = kRGBA_8888_SkColorType;
203 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500204 break;
205 }
206 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400207 colorType = kRGBA_8888_SkColorType;
208 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500209 break;
210 }
Romain Guy9505a652016-12-14 09:43:50 -0800211 case PIXEL_FORMAT_RGBA_FP16: {
212 colorType = kRGBA_F16_SkColorType;
213 alphaType = kPremul_SkAlphaType;
214 break;
215 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500216 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400217 colorType = kRGB_565_SkColorType;
218 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500219 break;
220 }
221 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500222 return NULL;
223 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800224 }
Romain Guy26a2b972017-04-17 09:39:51 -0700225
226 sk_sp<SkColorSpace> colorSpace;
227 if (screenshot->getDataSpace() == HAL_DATASPACE_DISPLAY_P3) {
228 colorSpace = SkColorSpace::MakeRGB(
229 SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
230 } else {
231 colorSpace = SkColorSpace::MakeSRGB();
232 }
233
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400234 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
235 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700236 colorType,
237 alphaType,
Romain Guy26a2b972017-04-17 09:39:51 -0700238 colorSpace);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800239
John Reckf29ed282015-04-07 07:32:03 -0700240 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500241 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
242
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400243 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700244 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800245 }
246
sergeyvc1c54062016-10-19 18:47:26 -0700247 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700248 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
Leon Scroggins IIIf51a80d2017-07-12 10:46:35 -0400249 screenshotInfo, rowBytes);
Ben Wagner60126ef2015-08-07 12:13:48 -0400250 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700251 bitmap->setImmutable();
252 return bitmap::createBitmap(env, bitmap,
253 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800254}
255
Dan Stoza9890e3412014-05-22 16:12:54 -0700256static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
257 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
258 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800259 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
260 if (displayToken != NULL) {
261 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
262 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700263 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
264 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
265 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
266 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
267 Rect sourceCrop(left, top, right, bottom);
268
Mathias Agopian0449a402013-03-01 23:01:51 -0800269 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800270 minLayer = INT32_MIN;
271 maxLayer = INT32_MAX;
Mathias Agopian0449a402013-03-01 23:01:51 -0800272 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700273 ScreenshotClient::capture(displayToken,
274 consumer->getIGraphicBufferProducer(), sourceCrop,
Robert Carr7f6e9862017-01-31 09:22:14 -0800275 width, height, minLayer, maxLayer,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800276 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800277 }
278 }
279}
280
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800281static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
282 SurfaceComposerClient::openGlobalTransaction();
283}
284
Robert Carre9953b12016-05-23 20:52:04 -0700285
286static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
287 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800288}
289
290static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
291 SurfaceComposerClient::setAnimationTransaction();
292}
293
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000294static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800295 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
296 status_t err = ctrl->setLayer(zorder);
297 if (err < 0 && err != NO_INIT) {
298 doThrowIAE(env);
299 }
300}
301
Robert Carraf422a82017-04-10 18:34:33 -0700302static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong nativeObject,
303 jobject relativeTo, jint zorder) {
304 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
305 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
306
307 ctrl->setRelativeLayer(handle, zorder);
308}
309
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000310static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800311 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
312 status_t err = ctrl->setPosition(x, y);
313 if (err < 0 && err != NO_INIT) {
314 doThrowIAE(env);
315 }
316}
317
Robert Carr6da3cc02016-06-16 15:17:07 -0700318static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700319 jlong nativeObject) {
320 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700321 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700322 if (err < 0 && err != NO_INIT) {
323 doThrowIAE(env);
324 }
325}
326
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000327static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800328 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
329 status_t err = ctrl->setSize(w, h);
330 if (err < 0 && err != NO_INIT) {
331 doThrowIAE(env);
332 }
333}
334
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000335static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800336 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
337 status_t err = ctrl->setFlags(flags, mask);
338 if (err < 0 && err != NO_INIT) {
339 doThrowIAE(env);
340 }
341}
342
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000343static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800344 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
345 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
346 if (!region) {
347 doThrowIAE(env);
348 return;
349 }
350
351 const SkIRect& b(region->getBounds());
352 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
353 if (region->isComplex()) {
354 SkRegion::Iterator it(*region);
355 while (!it.done()) {
356 const SkIRect& r(it.rect());
357 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
358 it.next();
359 }
360 }
361
362 status_t err = ctrl->setTransparentRegionHint(reg);
363 if (err < 0 && err != NO_INIT) {
364 doThrowIAE(env);
365 }
366}
367
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000368static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800369 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
370 status_t err = ctrl->setAlpha(alpha);
371 if (err < 0 && err != NO_INIT) {
372 doThrowIAE(env);
373 }
374}
375
chaviw0dd03f52017-08-25 12:15:26 -0700376static void nativeSetColor(JNIEnv* env, jclass clazz, jlong nativeObject, jfloatArray fColor) {
377 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
378 float* floatColors = env->GetFloatArrayElements(fColor, 0);
379 half3 color(floatColors[0], floatColors[1], floatColors[2]);
380 status_t err = ctrl->setColor(color);
381 if (err < 0 && err != NO_INIT) {
382 doThrowIAE(env);
383 }
384}
385
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000386static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800387 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800388 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr0edf18f2017-02-21 20:01:47 -0800389 status_t err = ctrl->setMatrix(dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800390 if (err < 0 && err != NO_INIT) {
391 doThrowIAE(env);
392 }
393}
394
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000395static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800396 jint l, jint t, jint r, jint b) {
397 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
398 Rect crop(l, t, r, b);
399 status_t err = ctrl->setCrop(crop);
400 if (err < 0 && err != NO_INIT) {
401 doThrowIAE(env);
402 }
403}
404
Pablo Ceballos27982e62016-03-09 10:50:45 -0800405static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
406 jint l, jint t, jint r, jint b) {
407 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
408 Rect crop(l, t, r, b);
409 status_t err = ctrl->setFinalCrop(crop);
410 if (err < 0 && err != NO_INIT) {
411 doThrowIAE(env);
412 }
413}
414
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000415static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800416 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
417 status_t err = ctrl->setLayerStack(layerStack);
418 if (err < 0 && err != NO_INIT) {
419 doThrowIAE(env);
420 }
421}
422
423static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
424 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
425 return javaObjectForIBinder(env, token);
426}
427
428static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
429 jboolean secure) {
430 ScopedUtfChars name(env, nameObj);
431 sp<IBinder> token(SurfaceComposerClient::createDisplay(
432 String8(name.c_str()), bool(secure)));
433 return javaObjectForIBinder(env, token);
434}
435
Jesse Hall6a6bc212013-08-08 12:15:03 -0700436static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
437 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
438 if (token == NULL) return;
439 SurfaceComposerClient::destroyDisplay(token);
440}
441
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800442static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000443 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800444 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
445 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800446 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800448 if (sur != NULL) {
449 bufferProducer = sur->getIGraphicBufferProducer();
450 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700451 status_t err = SurfaceComposerClient::setDisplaySurface(token,
452 bufferProducer);
453 if (err != NO_ERROR) {
454 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
455 " Surface created with singleBufferMode?");
456 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800457}
458
459static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
460 jobject tokenObj, jint layerStack) {
461 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
462 if (token == NULL) return;
463
464 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
465}
466
467static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
468 jobject tokenObj, jint orientation,
469 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
470 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
471 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
472 if (token == NULL) return;
473 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
474 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
475 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
476}
477
Michael Wright01e840f2014-06-26 16:03:25 -0700478static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
479 jobject tokenObj, jint width, jint height) {
480 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
481 if (token == NULL) return;
482 SurfaceComposerClient::setDisplaySize(token, width, height);
483}
484
Dan Stoza00101052014-05-02 15:23:40 -0700485static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
486 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800487 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700488 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800489
Dan Stoza00101052014-05-02 15:23:40 -0700490 Vector<DisplayInfo> configs;
491 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
492 configs.size() == 0) {
493 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800494 }
495
Dan Stoza00101052014-05-02 15:23:40 -0700496 jobjectArray configArray = env->NewObjectArray(configs.size(),
497 gPhysicalDisplayInfoClassInfo.clazz, NULL);
498
499 for (size_t c = 0; c < configs.size(); ++c) {
500 const DisplayInfo& info = configs[c];
501 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
502 gPhysicalDisplayInfoClassInfo.ctor);
503 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
504 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
505 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
506 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
507 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
508 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
509 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700510 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
511 info.appVsyncOffset);
512 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
513 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700514 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
515 env->DeleteLocalRef(infoObj);
516 }
517
518 return configArray;
519}
520
521static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
522 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
523 if (token == NULL) return -1;
524 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
525}
526
527static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
528 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
529 if (token == NULL) return JNI_FALSE;
530 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
531 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800532}
533
Michael Wright1c9977b2016-07-12 13:30:10 -0700534static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
535 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
536 if (token == NULL) return NULL;
537 Vector<android_color_mode_t> colorModes;
538 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
539 colorModes.isEmpty()) {
540 return NULL;
541 }
542
543 jintArray colorModesArray = env->NewIntArray(colorModes.size());
544 if (colorModesArray == NULL) {
545 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
546 return NULL;
547 }
548 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
549 for (size_t i = 0; i < colorModes.size(); i++) {
550 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
551 }
552 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
553 return colorModesArray;
554}
555
556static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
557 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
558 if (token == NULL) return -1;
559 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
560}
561
562static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
563 jobject tokenObj, jint colorMode) {
564 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
565 if (token == NULL) return JNI_FALSE;
566 status_t err = SurfaceComposerClient::setActiveColorMode(token,
567 static_cast<android_color_mode_t>(colorMode));
568 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
569}
570
Prashant Malanic55929a2014-05-25 01:59:21 -0700571static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800572 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
573 if (token == NULL) return;
574
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700575 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700576 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700577 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800578}
579
Svetoslav1376d602014-03-13 11:17:26 -0700580static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
581 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
582 status_t err = ctrl->clearLayerFrameStats();
583
584 if (err < 0 && err != NO_INIT) {
585 doThrowIAE(env);
586 }
587
588 // The other end is not ready, just report we failed.
589 if (err == NO_INIT) {
590 return JNI_FALSE;
591 }
592
593 return JNI_TRUE;
594}
595
596static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
597 jobject outStats) {
598 FrameStats stats;
599
600 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
601 status_t err = ctrl->getLayerFrameStats(&stats);
602 if (err < 0 && err != NO_INIT) {
603 doThrowIAE(env);
604 }
605
606 // The other end is not ready, fine just return empty stats.
607 if (err == NO_INIT) {
608 return JNI_FALSE;
609 }
610
611 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
612 size_t frameCount = stats.desiredPresentTimesNano.size();
613
614 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
615 if (postedTimesNanoDst == NULL) {
616 return JNI_FALSE;
617 }
618
619 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
620 if (presentedTimesNanoDst == NULL) {
621 return JNI_FALSE;
622 }
623
624 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
625 if (readyTimesNanoDst == NULL) {
626 return JNI_FALSE;
627 }
628
629 nsecs_t postedTimesNanoSrc[frameCount];
630 nsecs_t presentedTimesNanoSrc[frameCount];
631 nsecs_t readyTimesNanoSrc[frameCount];
632
633 for (size_t i = 0; i < frameCount; i++) {
634 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
635 if (postedTimeNano == INT64_MAX) {
636 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
637 }
638 postedTimesNanoSrc[i] = postedTimeNano;
639
640 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
641 if (presentedTimeNano == INT64_MAX) {
642 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
643 }
644 presentedTimesNanoSrc[i] = presentedTimeNano;
645
646 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
647 if (readyTimeNano == INT64_MAX) {
648 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
649 }
650 readyTimesNanoSrc[i] = readyTimeNano;
651 }
652
653 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
654 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
655 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
656
657 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
658 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
659
660 if (env->ExceptionCheck()) {
661 return JNI_FALSE;
662 }
663
664 return JNI_TRUE;
665}
666
667static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
668 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
669
670 if (err < 0 && err != NO_INIT) {
671 doThrowIAE(env);
672 }
673
674 // The other end is not ready, just report we failed.
675 if (err == NO_INIT) {
676 return JNI_FALSE;
677 }
678
679 return JNI_TRUE;
680}
681
682static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
683 FrameStats stats;
684
685 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
686 if (err < 0 && err != NO_INIT) {
687 doThrowIAE(env);
688 }
689
690 // The other end is not ready, fine just return empty stats.
691 if (err == NO_INIT) {
692 return JNI_FALSE;
693 }
694
695 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
696 size_t frameCount = stats.desiredPresentTimesNano.size();
697
698 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
699 if (presentedTimesNanoDst == NULL) {
700 return JNI_FALSE;
701 }
702
703 nsecs_t presentedTimesNanoSrc[frameCount];
704
705 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700706 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700707 if (presentedTimeNano == INT64_MAX) {
708 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
709 }
710 presentedTimesNanoSrc[i] = presentedTimeNano;
711 }
712
713 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
714
715 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
716 presentedTimesNanoDst);
717
718 if (env->ExceptionCheck()) {
719 return JNI_FALSE;
720 }
721
722 return JNI_TRUE;
723}
724
Rob Carr64e516f2015-10-29 00:20:45 +0000725static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
726 jobject handleObject, jlong frameNumber) {
727 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
728 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
729
730 ctrl->deferTransactionUntil(handle, frameNumber);
731}
732
Robert Carrd5c7dd62017-03-08 10:39:30 -0800733static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong nativeObject,
734 jlong surfaceObject, jlong frameNumber) {
735 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
736 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
737
738 ctrl->deferTransactionUntil(barrier, frameNumber);
739}
740
741static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong nativeObject,
742 jobject newParentObject) {
743 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
744 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
745
746 ctrl->reparentChildren(handle);
747}
748
chaviw63542382017-08-17 17:39:29 -0700749static void nativeReparentChild(JNIEnv* env, jclass clazz, jlong nativeObject,
750 jobject newParentObject, jobject childObject) {
751 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
752 sp<IBinder> parentHandle = ibinderForJavaObject(env, newParentObject);
753 sp<IBinder> childHandle = ibinderForJavaObject(env, childObject);
754
755 ctrl->reparentChild(parentHandle, childHandle);
756}
757
Robert Carrd5c7dd62017-03-08 10:39:30 -0800758static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong nativeObject) {
759 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
760 ctrl->detachChildren();
761}
762
Robert Carr1ca6a332016-04-11 18:00:43 -0700763static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
764 jint scalingMode) {
765 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
766
767 ctrl->setOverrideScalingMode(scalingMode);
768}
769
Rob Carr64e516f2015-10-29 00:20:45 +0000770static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
771 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
772
773 return javaObjectForIBinder(env, ctrl->getHandle());
774}
775
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700776static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
777 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
778 if (token == NULL) return NULL;
779
780 HdrCapabilities capabilities;
781 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
782
783 const auto& types = capabilities.getSupportedHdrTypes();
784 auto typesArray = env->NewIntArray(types.size());
785 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
786
Michael Wright9ff94c02016-03-30 18:05:40 -0700787 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700788 typesArray, capabilities.getDesiredMaxLuminance(),
789 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
790}
791
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800792// ----------------------------------------------------------------------------
793
Daniel Micay76f6a862015-09-19 17:31:01 -0400794static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500795 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800796 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000797 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800798 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000799 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800800 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800801 {"nativeDisconnect", "(J)V",
802 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700803 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800804 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700805 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800806 (void*)nativeScreenshot },
807 {"nativeOpenTransaction", "()V",
808 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700809 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800810 (void*)nativeCloseTransaction },
811 {"nativeSetAnimationTransaction", "()V",
812 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000813 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800814 (void*)nativeSetLayer },
Robert Carraf422a82017-04-10 18:34:33 -0700815 {"nativeSetRelativeLayer", "(JLandroid/os/IBinder;I)V",
816 (void*)nativeSetRelativeLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000817 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800818 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700819 {"nativeSetGeometryAppliesWithResize", "(J)V",
820 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000821 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800822 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000823 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800824 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000825 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800826 (void*)nativeSetAlpha },
chaviw0dd03f52017-08-25 12:15:26 -0700827 {"nativeSetColor", "(J[F)V",
828 (void*)nativeSetColor },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000829 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800830 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000831 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800832 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000833 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800834 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800835 {"nativeSetFinalCrop", "(JIIII)V",
836 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000837 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800838 (void*)nativeSetLayerStack },
839 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
840 (void*)nativeGetBuiltInDisplay },
841 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
842 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700843 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
844 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000845 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800846 (void*)nativeSetDisplaySurface },
847 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
848 (void*)nativeSetDisplayLayerStack },
849 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
850 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700851 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
852 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700853 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
854 (void*)nativeGetDisplayConfigs },
855 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
856 (void*)nativeGetActiveConfig },
857 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
858 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700859 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
860 (void*)nativeGetDisplayColorModes},
861 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
862 (void*)nativeGetActiveColorMode},
863 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
864 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700865 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
866 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700867 {"nativeClearContentFrameStats", "(J)Z",
868 (void*)nativeClearContentFrameStats },
869 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
870 (void*)nativeGetContentFrameStats },
871 {"nativeClearAnimationFrameStats", "()Z",
872 (void*)nativeClearAnimationFrameStats },
873 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
874 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700875 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
876 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000877 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
878 (void*)nativeDeferTransactionUntil },
Robert Carrd5c7dd62017-03-08 10:39:30 -0800879 {"nativeDeferTransactionUntilSurface", "(JJJ)V",
880 (void*)nativeDeferTransactionUntilSurface },
881 {"nativeReparentChildren", "(JLandroid/os/IBinder;)V",
882 (void*)nativeReparentChildren } ,
chaviw63542382017-08-17 17:39:29 -0700883 {"nativeReparentChild", "(JLandroid/os/IBinder;Landroid/os/IBinder;)V",
884 (void*)nativeReparentChild },
Robert Carrd5c7dd62017-03-08 10:39:30 -0800885 {"nativeSeverChildren", "(J)V",
886 (void*)nativeSeverChildren } ,
Robert Carr1ca6a332016-04-11 18:00:43 -0700887 {"nativeSetOverrideScalingMode", "(JI)V",
888 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000889 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700890 (void*)nativeGetHandle },
Robert Carr6486d312017-01-09 19:48:29 -0800891 {"nativeScreenshotToBuffer",
892 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
893 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800894};
895
896int register_android_view_SurfaceControl(JNIEnv* env)
897{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800898 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800899 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
900
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800901 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
902 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
903 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
904 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
905 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
906 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
907 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
908 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
909 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
910 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
911 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
912 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
913 clazz, "appVsyncOffsetNanos", "J");
914 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
915 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700916
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800917 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
918 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
919 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
920 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
921 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700922
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800923 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
924 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
925 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700926 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
927
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800928 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
929 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
930 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700931 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
932
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800933 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
934 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
935 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700936 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
937
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700938 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
939 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
940 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
941 "([IFFF)V");
942
Robert Carr6486d312017-01-09 19:48:29 -0800943 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
944 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
945 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
946 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
947
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800948 return err;
949}
950
951};