blob: 6932702f73c631b1b29e2145627d616a5812b9b3 [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(),
170 (void*)buffer.get());
171}
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,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800265 width, height, uint32_t(minLayer), uint32_t(maxLayer),
266 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
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000292static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800293 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
294 status_t err = ctrl->setPosition(x, y);
295 if (err < 0 && err != NO_INIT) {
296 doThrowIAE(env);
297 }
298}
299
Robert Carr6da3cc02016-06-16 15:17:07 -0700300static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700301 jlong nativeObject) {
302 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700303 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700304 if (err < 0 && err != NO_INIT) {
305 doThrowIAE(env);
306 }
307}
308
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000309static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800310 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
311 status_t err = ctrl->setSize(w, h);
312 if (err < 0 && err != NO_INIT) {
313 doThrowIAE(env);
314 }
315}
316
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000317static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800318 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
319 status_t err = ctrl->setFlags(flags, mask);
320 if (err < 0 && err != NO_INIT) {
321 doThrowIAE(env);
322 }
323}
324
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000325static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800326 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
327 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
328 if (!region) {
329 doThrowIAE(env);
330 return;
331 }
332
333 const SkIRect& b(region->getBounds());
334 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
335 if (region->isComplex()) {
336 SkRegion::Iterator it(*region);
337 while (!it.done()) {
338 const SkIRect& r(it.rect());
339 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
340 it.next();
341 }
342 }
343
344 status_t err = ctrl->setTransparentRegionHint(reg);
345 if (err < 0 && err != NO_INIT) {
346 doThrowIAE(env);
347 }
348}
349
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000350static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800351 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
352 status_t err = ctrl->setAlpha(alpha);
353 if (err < 0 && err != NO_INIT) {
354 doThrowIAE(env);
355 }
356}
357
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000358static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800359 jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
360 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
361 status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
362 if (err < 0 && err != NO_INIT) {
363 doThrowIAE(env);
364 }
365}
366
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000367static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800368 jint l, jint t, jint r, jint b) {
369 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
370 Rect crop(l, t, r, b);
371 status_t err = ctrl->setCrop(crop);
372 if (err < 0 && err != NO_INIT) {
373 doThrowIAE(env);
374 }
375}
376
Pablo Ceballos27982e62016-03-09 10:50:45 -0800377static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
378 jint l, jint t, jint r, jint b) {
379 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
380 Rect crop(l, t, r, b);
381 status_t err = ctrl->setFinalCrop(crop);
382 if (err < 0 && err != NO_INIT) {
383 doThrowIAE(env);
384 }
385}
386
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000387static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800388 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
389 status_t err = ctrl->setLayerStack(layerStack);
390 if (err < 0 && err != NO_INIT) {
391 doThrowIAE(env);
392 }
393}
394
395static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
396 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
397 return javaObjectForIBinder(env, token);
398}
399
400static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
401 jboolean secure) {
402 ScopedUtfChars name(env, nameObj);
403 sp<IBinder> token(SurfaceComposerClient::createDisplay(
404 String8(name.c_str()), bool(secure)));
405 return javaObjectForIBinder(env, token);
406}
407
Jesse Hall6a6bc212013-08-08 12:15:03 -0700408static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
409 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
410 if (token == NULL) return;
411 SurfaceComposerClient::destroyDisplay(token);
412}
413
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000415 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800416 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
417 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800418 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800419 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800420 if (sur != NULL) {
421 bufferProducer = sur->getIGraphicBufferProducer();
422 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700423 status_t err = SurfaceComposerClient::setDisplaySurface(token,
424 bufferProducer);
425 if (err != NO_ERROR) {
426 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
427 " Surface created with singleBufferMode?");
428 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800429}
430
431static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
432 jobject tokenObj, jint layerStack) {
433 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
434 if (token == NULL) return;
435
436 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
437}
438
439static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
440 jobject tokenObj, jint orientation,
441 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
442 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
443 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
444 if (token == NULL) return;
445 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
446 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
447 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
448}
449
Michael Wright01e840f2014-06-26 16:03:25 -0700450static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
451 jobject tokenObj, jint width, jint height) {
452 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
453 if (token == NULL) return;
454 SurfaceComposerClient::setDisplaySize(token, width, height);
455}
456
Dan Stoza00101052014-05-02 15:23:40 -0700457static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
458 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800459 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700460 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800461
Dan Stoza00101052014-05-02 15:23:40 -0700462 Vector<DisplayInfo> configs;
463 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
464 configs.size() == 0) {
465 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800466 }
467
Dan Stoza00101052014-05-02 15:23:40 -0700468 jobjectArray configArray = env->NewObjectArray(configs.size(),
469 gPhysicalDisplayInfoClassInfo.clazz, NULL);
470
471 for (size_t c = 0; c < configs.size(); ++c) {
472 const DisplayInfo& info = configs[c];
473 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
474 gPhysicalDisplayInfoClassInfo.ctor);
475 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
476 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
477 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
478 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
479 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
480 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
481 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700482 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
483 info.appVsyncOffset);
484 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
485 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700486 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
487 env->DeleteLocalRef(infoObj);
488 }
489
490 return configArray;
491}
492
493static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
494 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
495 if (token == NULL) return -1;
496 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
497}
498
499static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
500 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
501 if (token == NULL) return JNI_FALSE;
502 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
503 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800504}
505
Michael Wright1c9977b2016-07-12 13:30:10 -0700506static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
507 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
508 if (token == NULL) return NULL;
509 Vector<android_color_mode_t> colorModes;
510 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
511 colorModes.isEmpty()) {
512 return NULL;
513 }
514
515 jintArray colorModesArray = env->NewIntArray(colorModes.size());
516 if (colorModesArray == NULL) {
517 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
518 return NULL;
519 }
520 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
521 for (size_t i = 0; i < colorModes.size(); i++) {
522 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
523 }
524 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
525 return colorModesArray;
526}
527
528static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
529 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
530 if (token == NULL) return -1;
531 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
532}
533
534static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
535 jobject tokenObj, jint colorMode) {
536 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
537 if (token == NULL) return JNI_FALSE;
538 status_t err = SurfaceComposerClient::setActiveColorMode(token,
539 static_cast<android_color_mode_t>(colorMode));
540 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
541}
542
Prashant Malanic55929a2014-05-25 01:59:21 -0700543static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800544 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
545 if (token == NULL) return;
546
Prashant Malanic55929a2014-05-25 01:59:21 -0700547 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
548 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800549}
550
Svetoslav1376d602014-03-13 11:17:26 -0700551static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
552 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
553 status_t err = ctrl->clearLayerFrameStats();
554
555 if (err < 0 && err != NO_INIT) {
556 doThrowIAE(env);
557 }
558
559 // The other end is not ready, just report we failed.
560 if (err == NO_INIT) {
561 return JNI_FALSE;
562 }
563
564 return JNI_TRUE;
565}
566
567static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
568 jobject outStats) {
569 FrameStats stats;
570
571 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
572 status_t err = ctrl->getLayerFrameStats(&stats);
573 if (err < 0 && err != NO_INIT) {
574 doThrowIAE(env);
575 }
576
577 // The other end is not ready, fine just return empty stats.
578 if (err == NO_INIT) {
579 return JNI_FALSE;
580 }
581
582 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
583 size_t frameCount = stats.desiredPresentTimesNano.size();
584
585 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
586 if (postedTimesNanoDst == NULL) {
587 return JNI_FALSE;
588 }
589
590 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
591 if (presentedTimesNanoDst == NULL) {
592 return JNI_FALSE;
593 }
594
595 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
596 if (readyTimesNanoDst == NULL) {
597 return JNI_FALSE;
598 }
599
600 nsecs_t postedTimesNanoSrc[frameCount];
601 nsecs_t presentedTimesNanoSrc[frameCount];
602 nsecs_t readyTimesNanoSrc[frameCount];
603
604 for (size_t i = 0; i < frameCount; i++) {
605 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
606 if (postedTimeNano == INT64_MAX) {
607 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
608 }
609 postedTimesNanoSrc[i] = postedTimeNano;
610
611 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
612 if (presentedTimeNano == INT64_MAX) {
613 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
614 }
615 presentedTimesNanoSrc[i] = presentedTimeNano;
616
617 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
618 if (readyTimeNano == INT64_MAX) {
619 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
620 }
621 readyTimesNanoSrc[i] = readyTimeNano;
622 }
623
624 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
625 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
626 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
627
628 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
629 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
630
631 if (env->ExceptionCheck()) {
632 return JNI_FALSE;
633 }
634
635 return JNI_TRUE;
636}
637
638static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
639 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
640
641 if (err < 0 && err != NO_INIT) {
642 doThrowIAE(env);
643 }
644
645 // The other end is not ready, just report we failed.
646 if (err == NO_INIT) {
647 return JNI_FALSE;
648 }
649
650 return JNI_TRUE;
651}
652
653static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
654 FrameStats stats;
655
656 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
657 if (err < 0 && err != NO_INIT) {
658 doThrowIAE(env);
659 }
660
661 // The other end is not ready, fine just return empty stats.
662 if (err == NO_INIT) {
663 return JNI_FALSE;
664 }
665
666 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
667 size_t frameCount = stats.desiredPresentTimesNano.size();
668
669 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
670 if (presentedTimesNanoDst == NULL) {
671 return JNI_FALSE;
672 }
673
674 nsecs_t presentedTimesNanoSrc[frameCount];
675
676 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700677 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700678 if (presentedTimeNano == INT64_MAX) {
679 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
680 }
681 presentedTimesNanoSrc[i] = presentedTimeNano;
682 }
683
684 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
685
686 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
687 presentedTimesNanoDst);
688
689 if (env->ExceptionCheck()) {
690 return JNI_FALSE;
691 }
692
693 return JNI_TRUE;
694}
695
Rob Carr64e516f2015-10-29 00:20:45 +0000696
697static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
698 jobject handleObject, jlong frameNumber) {
699 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
700 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
701
702 ctrl->deferTransactionUntil(handle, frameNumber);
703}
704
Robert Carr1ca6a332016-04-11 18:00:43 -0700705static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
706 jint scalingMode) {
707 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
708
709 ctrl->setOverrideScalingMode(scalingMode);
710}
711
Rob Carr64e516f2015-10-29 00:20:45 +0000712static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
713 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
714
715 return javaObjectForIBinder(env, ctrl->getHandle());
716}
717
Robert Carr6da3cc02016-06-16 15:17:07 -0700718static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) {
719 bool out = false;
720 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
721 status_t status = ctrl->getTransformToDisplayInverse(&out);
722 if (status != NO_ERROR) {
723 return false;
724 }
725 return out;
726}
727
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700728static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
729 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
730 if (token == NULL) return NULL;
731
732 HdrCapabilities capabilities;
733 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
734
735 const auto& types = capabilities.getSupportedHdrTypes();
736 auto typesArray = env->NewIntArray(types.size());
737 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
738
Michael Wright9ff94c02016-03-30 18:05:40 -0700739 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700740 typesArray, capabilities.getDesiredMaxLuminance(),
741 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
742}
743
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800744// ----------------------------------------------------------------------------
745
Daniel Micay76f6a862015-09-19 17:31:01 -0400746static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500747 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800748 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000749 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800750 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000751 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800752 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800753 {"nativeDisconnect", "(J)V",
754 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700755 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800756 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700757 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800758 (void*)nativeScreenshot },
759 {"nativeOpenTransaction", "()V",
760 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700761 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800762 (void*)nativeCloseTransaction },
763 {"nativeSetAnimationTransaction", "()V",
764 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000765 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800766 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000767 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800768 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700769 {"nativeSetGeometryAppliesWithResize", "(J)V",
770 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000771 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800772 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000773 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800774 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000775 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800776 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000777 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800778 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000779 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800780 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000781 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800782 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800783 {"nativeSetFinalCrop", "(JIIII)V",
784 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000785 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800786 (void*)nativeSetLayerStack },
787 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
788 (void*)nativeGetBuiltInDisplay },
789 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
790 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700791 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
792 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000793 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800794 (void*)nativeSetDisplaySurface },
795 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
796 (void*)nativeSetDisplayLayerStack },
797 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
798 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700799 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
800 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700801 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
802 (void*)nativeGetDisplayConfigs },
803 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
804 (void*)nativeGetActiveConfig },
805 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
806 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700807 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
808 (void*)nativeGetDisplayColorModes},
809 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
810 (void*)nativeGetActiveColorMode},
811 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
812 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700813 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
814 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700815 {"nativeClearContentFrameStats", "(J)Z",
816 (void*)nativeClearContentFrameStats },
817 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
818 (void*)nativeGetContentFrameStats },
819 {"nativeClearAnimationFrameStats", "()Z",
820 (void*)nativeClearAnimationFrameStats },
821 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
822 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700823 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
824 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000825 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
826 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700827 {"nativeSetOverrideScalingMode", "(JI)V",
828 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000829 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700830 (void*)nativeGetHandle },
831 {"nativeGetTransformToDisplayInverse", "(J)Z",
Robert Carr6486d312017-01-09 19:48:29 -0800832 (void*)nativeGetTransformToDisplayInverse },
833 {"nativeScreenshotToBuffer",
834 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
835 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800836};
837
838int register_android_view_SurfaceControl(JNIEnv* env)
839{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800840 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800841 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
842
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800843 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
844 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
845 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
846 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
847 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
848 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
849 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
850 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
851 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
852 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
853 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
854 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
855 clazz, "appVsyncOffsetNanos", "J");
856 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
857 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700858
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800859 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
860 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
861 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
862 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
863 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700864
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800865 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
866 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
867 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700868 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
869
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800870 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
871 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
872 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700873 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
874
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800875 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
876 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
877 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700878 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
879
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700880 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
881 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
882 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
883 "([IFFF)V");
884
Robert Carr6486d312017-01-09 19:48:29 -0800885 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
886 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
887 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
888 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
889
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800890 return err;
891}
892
893};