blob: 8b82314476430c92f390e670c07b2b054cef7c09 [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 }
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400224 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
225 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700226 colorType,
227 alphaType,
228 GraphicsJNI::defaultColorSpace());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800229
John Reckf29ed282015-04-07 07:32:03 -0700230 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500231 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
232
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400233 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700234 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800235 }
236
sergeyvc1c54062016-10-19 18:47:26 -0700237 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700238 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
239 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400240 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700241 bitmap->setImmutable();
242 return bitmap::createBitmap(env, bitmap,
243 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800244}
245
Dan Stoza9890e3412014-05-22 16:12:54 -0700246static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
247 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
248 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800249 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
250 if (displayToken != NULL) {
251 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
252 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700253 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
254 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
255 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
256 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
257 Rect sourceCrop(left, top, right, bottom);
258
Mathias Agopian0449a402013-03-01 23:01:51 -0800259 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800260 minLayer = INT32_MIN;
261 maxLayer = INT32_MAX;
Mathias Agopian0449a402013-03-01 23:01:51 -0800262 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700263 ScreenshotClient::capture(displayToken,
264 consumer->getIGraphicBufferProducer(), sourceCrop,
Robert Carr7f6e9862017-01-31 09:22:14 -0800265 width, height, minLayer, maxLayer,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800266 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800267 }
268 }
269}
270
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800271static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
272 SurfaceComposerClient::openGlobalTransaction();
273}
274
Robert Carre9953b12016-05-23 20:52:04 -0700275
276static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
277 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800278}
279
280static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
281 SurfaceComposerClient::setAnimationTransaction();
282}
283
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000284static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800285 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
286 status_t err = ctrl->setLayer(zorder);
287 if (err < 0 && err != NO_INIT) {
288 doThrowIAE(env);
289 }
290}
291
Robert Carraf422a82017-04-10 18:34:33 -0700292static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong nativeObject,
293 jobject relativeTo, jint zorder) {
294 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
295 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
296
297 ctrl->setRelativeLayer(handle, zorder);
298}
299
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000300static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800301 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
302 status_t err = ctrl->setPosition(x, y);
303 if (err < 0 && err != NO_INIT) {
304 doThrowIAE(env);
305 }
306}
307
Robert Carr6da3cc02016-06-16 15:17:07 -0700308static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700309 jlong nativeObject) {
310 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700311 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700312 if (err < 0 && err != NO_INIT) {
313 doThrowIAE(env);
314 }
315}
316
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000317static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800318 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
319 status_t err = ctrl->setSize(w, h);
320 if (err < 0 && err != NO_INIT) {
321 doThrowIAE(env);
322 }
323}
324
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000325static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800326 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
327 status_t err = ctrl->setFlags(flags, mask);
328 if (err < 0 && err != NO_INIT) {
329 doThrowIAE(env);
330 }
331}
332
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000333static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800334 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
335 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
336 if (!region) {
337 doThrowIAE(env);
338 return;
339 }
340
341 const SkIRect& b(region->getBounds());
342 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
343 if (region->isComplex()) {
344 SkRegion::Iterator it(*region);
345 while (!it.done()) {
346 const SkIRect& r(it.rect());
347 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
348 it.next();
349 }
350 }
351
352 status_t err = ctrl->setTransparentRegionHint(reg);
353 if (err < 0 && err != NO_INIT) {
354 doThrowIAE(env);
355 }
356}
357
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000358static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800359 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
360 status_t err = ctrl->setAlpha(alpha);
361 if (err < 0 && err != NO_INIT) {
362 doThrowIAE(env);
363 }
364}
365
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000366static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800367 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800368 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr0edf18f2017-02-21 20:01:47 -0800369 status_t err = ctrl->setMatrix(dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800370 if (err < 0 && err != NO_INIT) {
371 doThrowIAE(env);
372 }
373}
374
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000375static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800376 jint l, jint t, jint r, jint b) {
377 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
378 Rect crop(l, t, r, b);
379 status_t err = ctrl->setCrop(crop);
380 if (err < 0 && err != NO_INIT) {
381 doThrowIAE(env);
382 }
383}
384
Pablo Ceballos27982e62016-03-09 10:50:45 -0800385static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
386 jint l, jint t, jint r, jint b) {
387 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
388 Rect crop(l, t, r, b);
389 status_t err = ctrl->setFinalCrop(crop);
390 if (err < 0 && err != NO_INIT) {
391 doThrowIAE(env);
392 }
393}
394
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000395static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800396 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
397 status_t err = ctrl->setLayerStack(layerStack);
398 if (err < 0 && err != NO_INIT) {
399 doThrowIAE(env);
400 }
401}
402
403static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
404 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
405 return javaObjectForIBinder(env, token);
406}
407
408static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
409 jboolean secure) {
410 ScopedUtfChars name(env, nameObj);
411 sp<IBinder> token(SurfaceComposerClient::createDisplay(
412 String8(name.c_str()), bool(secure)));
413 return javaObjectForIBinder(env, token);
414}
415
Jesse Hall6a6bc212013-08-08 12:15:03 -0700416static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
417 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
418 if (token == NULL) return;
419 SurfaceComposerClient::destroyDisplay(token);
420}
421
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800422static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000423 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800424 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
425 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800426 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800427 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800428 if (sur != NULL) {
429 bufferProducer = sur->getIGraphicBufferProducer();
430 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700431 status_t err = SurfaceComposerClient::setDisplaySurface(token,
432 bufferProducer);
433 if (err != NO_ERROR) {
434 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
435 " Surface created with singleBufferMode?");
436 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800437}
438
439static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
440 jobject tokenObj, jint layerStack) {
441 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
442 if (token == NULL) return;
443
444 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
445}
446
447static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
448 jobject tokenObj, jint orientation,
449 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
450 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
451 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
452 if (token == NULL) return;
453 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
454 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
455 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
456}
457
Michael Wright01e840f2014-06-26 16:03:25 -0700458static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
459 jobject tokenObj, jint width, jint height) {
460 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
461 if (token == NULL) return;
462 SurfaceComposerClient::setDisplaySize(token, width, height);
463}
464
Dan Stoza00101052014-05-02 15:23:40 -0700465static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
466 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800467 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700468 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800469
Dan Stoza00101052014-05-02 15:23:40 -0700470 Vector<DisplayInfo> configs;
471 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
472 configs.size() == 0) {
473 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800474 }
475
Dan Stoza00101052014-05-02 15:23:40 -0700476 jobjectArray configArray = env->NewObjectArray(configs.size(),
477 gPhysicalDisplayInfoClassInfo.clazz, NULL);
478
479 for (size_t c = 0; c < configs.size(); ++c) {
480 const DisplayInfo& info = configs[c];
481 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
482 gPhysicalDisplayInfoClassInfo.ctor);
483 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
484 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
485 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
486 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
487 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
488 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
489 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700490 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
491 info.appVsyncOffset);
492 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
493 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700494 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
495 env->DeleteLocalRef(infoObj);
496 }
497
498 return configArray;
499}
500
501static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
502 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
503 if (token == NULL) return -1;
504 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
505}
506
507static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
508 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
509 if (token == NULL) return JNI_FALSE;
510 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
511 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800512}
513
Michael Wright1c9977b2016-07-12 13:30:10 -0700514static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
515 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
516 if (token == NULL) return NULL;
517 Vector<android_color_mode_t> colorModes;
518 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
519 colorModes.isEmpty()) {
520 return NULL;
521 }
522
523 jintArray colorModesArray = env->NewIntArray(colorModes.size());
524 if (colorModesArray == NULL) {
525 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
526 return NULL;
527 }
528 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
529 for (size_t i = 0; i < colorModes.size(); i++) {
530 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
531 }
532 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
533 return colorModesArray;
534}
535
536static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
537 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
538 if (token == NULL) return -1;
539 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
540}
541
542static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
543 jobject tokenObj, jint colorMode) {
544 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
545 if (token == NULL) return JNI_FALSE;
546 status_t err = SurfaceComposerClient::setActiveColorMode(token,
547 static_cast<android_color_mode_t>(colorMode));
548 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
549}
550
Prashant Malanic55929a2014-05-25 01:59:21 -0700551static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800552 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
553 if (token == NULL) return;
554
Prashant Malanic55929a2014-05-25 01:59:21 -0700555 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
556 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800557}
558
Svetoslav1376d602014-03-13 11:17:26 -0700559static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
560 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
561 status_t err = ctrl->clearLayerFrameStats();
562
563 if (err < 0 && err != NO_INIT) {
564 doThrowIAE(env);
565 }
566
567 // The other end is not ready, just report we failed.
568 if (err == NO_INIT) {
569 return JNI_FALSE;
570 }
571
572 return JNI_TRUE;
573}
574
575static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
576 jobject outStats) {
577 FrameStats stats;
578
579 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
580 status_t err = ctrl->getLayerFrameStats(&stats);
581 if (err < 0 && err != NO_INIT) {
582 doThrowIAE(env);
583 }
584
585 // The other end is not ready, fine just return empty stats.
586 if (err == NO_INIT) {
587 return JNI_FALSE;
588 }
589
590 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
591 size_t frameCount = stats.desiredPresentTimesNano.size();
592
593 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
594 if (postedTimesNanoDst == NULL) {
595 return JNI_FALSE;
596 }
597
598 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
599 if (presentedTimesNanoDst == NULL) {
600 return JNI_FALSE;
601 }
602
603 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
604 if (readyTimesNanoDst == NULL) {
605 return JNI_FALSE;
606 }
607
608 nsecs_t postedTimesNanoSrc[frameCount];
609 nsecs_t presentedTimesNanoSrc[frameCount];
610 nsecs_t readyTimesNanoSrc[frameCount];
611
612 for (size_t i = 0; i < frameCount; i++) {
613 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
614 if (postedTimeNano == INT64_MAX) {
615 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
616 }
617 postedTimesNanoSrc[i] = postedTimeNano;
618
619 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
620 if (presentedTimeNano == INT64_MAX) {
621 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
622 }
623 presentedTimesNanoSrc[i] = presentedTimeNano;
624
625 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
626 if (readyTimeNano == INT64_MAX) {
627 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
628 }
629 readyTimesNanoSrc[i] = readyTimeNano;
630 }
631
632 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
633 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
634 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
635
636 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
637 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
638
639 if (env->ExceptionCheck()) {
640 return JNI_FALSE;
641 }
642
643 return JNI_TRUE;
644}
645
646static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
647 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
648
649 if (err < 0 && err != NO_INIT) {
650 doThrowIAE(env);
651 }
652
653 // The other end is not ready, just report we failed.
654 if (err == NO_INIT) {
655 return JNI_FALSE;
656 }
657
658 return JNI_TRUE;
659}
660
661static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
662 FrameStats stats;
663
664 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
665 if (err < 0 && err != NO_INIT) {
666 doThrowIAE(env);
667 }
668
669 // The other end is not ready, fine just return empty stats.
670 if (err == NO_INIT) {
671 return JNI_FALSE;
672 }
673
674 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
675 size_t frameCount = stats.desiredPresentTimesNano.size();
676
677 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
678 if (presentedTimesNanoDst == NULL) {
679 return JNI_FALSE;
680 }
681
682 nsecs_t presentedTimesNanoSrc[frameCount];
683
684 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700685 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700686 if (presentedTimeNano == INT64_MAX) {
687 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
688 }
689 presentedTimesNanoSrc[i] = presentedTimeNano;
690 }
691
692 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
693
694 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
695 presentedTimesNanoDst);
696
697 if (env->ExceptionCheck()) {
698 return JNI_FALSE;
699 }
700
701 return JNI_TRUE;
702}
703
Rob Carr64e516f2015-10-29 00:20:45 +0000704static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
705 jobject handleObject, jlong frameNumber) {
706 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
707 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
708
709 ctrl->deferTransactionUntil(handle, frameNumber);
710}
711
Robert Carrd5c7dd62017-03-08 10:39:30 -0800712static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong nativeObject,
713 jlong surfaceObject, jlong frameNumber) {
714 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
715 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
716
717 ctrl->deferTransactionUntil(barrier, frameNumber);
718}
719
720static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong nativeObject,
721 jobject newParentObject) {
722 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
723 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
724
725 ctrl->reparentChildren(handle);
726}
727
728static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong nativeObject) {
729 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
730 ctrl->detachChildren();
731}
732
Robert Carr1ca6a332016-04-11 18:00:43 -0700733static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
734 jint scalingMode) {
735 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
736
737 ctrl->setOverrideScalingMode(scalingMode);
738}
739
Rob Carr64e516f2015-10-29 00:20:45 +0000740static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
741 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
742
743 return javaObjectForIBinder(env, ctrl->getHandle());
744}
745
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700746static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
747 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
748 if (token == NULL) return NULL;
749
750 HdrCapabilities capabilities;
751 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
752
753 const auto& types = capabilities.getSupportedHdrTypes();
754 auto typesArray = env->NewIntArray(types.size());
755 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
756
Michael Wright9ff94c02016-03-30 18:05:40 -0700757 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700758 typesArray, capabilities.getDesiredMaxLuminance(),
759 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
760}
761
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800762// ----------------------------------------------------------------------------
763
Daniel Micay76f6a862015-09-19 17:31:01 -0400764static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500765 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800766 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000767 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800768 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000769 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800770 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800771 {"nativeDisconnect", "(J)V",
772 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700773 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800774 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700775 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800776 (void*)nativeScreenshot },
777 {"nativeOpenTransaction", "()V",
778 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700779 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800780 (void*)nativeCloseTransaction },
781 {"nativeSetAnimationTransaction", "()V",
782 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000783 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800784 (void*)nativeSetLayer },
Robert Carraf422a82017-04-10 18:34:33 -0700785 {"nativeSetRelativeLayer", "(JLandroid/os/IBinder;I)V",
786 (void*)nativeSetRelativeLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000787 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800788 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700789 {"nativeSetGeometryAppliesWithResize", "(J)V",
790 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000791 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800792 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000793 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800794 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000795 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800796 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000797 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800798 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000799 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800800 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000801 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800802 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800803 {"nativeSetFinalCrop", "(JIIII)V",
804 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000805 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800806 (void*)nativeSetLayerStack },
807 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
808 (void*)nativeGetBuiltInDisplay },
809 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
810 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700811 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
812 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000813 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800814 (void*)nativeSetDisplaySurface },
815 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
816 (void*)nativeSetDisplayLayerStack },
817 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
818 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700819 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
820 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700821 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
822 (void*)nativeGetDisplayConfigs },
823 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
824 (void*)nativeGetActiveConfig },
825 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
826 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700827 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
828 (void*)nativeGetDisplayColorModes},
829 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
830 (void*)nativeGetActiveColorMode},
831 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
832 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700833 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
834 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700835 {"nativeClearContentFrameStats", "(J)Z",
836 (void*)nativeClearContentFrameStats },
837 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
838 (void*)nativeGetContentFrameStats },
839 {"nativeClearAnimationFrameStats", "()Z",
840 (void*)nativeClearAnimationFrameStats },
841 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
842 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700843 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
844 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000845 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
846 (void*)nativeDeferTransactionUntil },
Robert Carrd5c7dd62017-03-08 10:39:30 -0800847 {"nativeDeferTransactionUntilSurface", "(JJJ)V",
848 (void*)nativeDeferTransactionUntilSurface },
849 {"nativeReparentChildren", "(JLandroid/os/IBinder;)V",
850 (void*)nativeReparentChildren } ,
851 {"nativeSeverChildren", "(J)V",
852 (void*)nativeSeverChildren } ,
Robert Carr1ca6a332016-04-11 18:00:43 -0700853 {"nativeSetOverrideScalingMode", "(JI)V",
854 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000855 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700856 (void*)nativeGetHandle },
Robert Carr6486d312017-01-09 19:48:29 -0800857 {"nativeScreenshotToBuffer",
858 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
859 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800860};
861
862int register_android_view_SurfaceControl(JNIEnv* env)
863{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800864 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800865 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
866
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800867 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
868 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
869 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
870 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
871 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
872 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
873 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
874 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
875 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
876 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
877 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
878 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
879 clazz, "appVsyncOffsetNanos", "J");
880 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
881 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700882
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800883 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
884 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
885 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
886 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
887 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700888
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800889 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
890 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
891 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700892 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
893
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800894 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
895 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
896 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700897 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
898
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800899 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
900 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
901 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700902 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
903
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700904 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
905 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
906 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
907 "([IFFF)V");
908
Robert Carr6486d312017-01-09 19:48:29 -0800909 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
910 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
911 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
912 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
913
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800914 return err;
915}
916
917};