blob: a3fef27a9c3af8fe0e5558b05a3ef3030f1e86a4 [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,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800101 jstring nameStr, jint w, jint h, jint format, jint flags) {
102 ScopedUtfChars name(env, nameStr);
103 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
104 sp<SurfaceControl> surface = client->createSurface(
105 String8(name.c_str()), w, h, format, flags);
106 if (surface == NULL) {
107 jniThrowException(env, OutOfResourcesException, NULL);
108 return 0;
109 }
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800110 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000111 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800112}
113
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000114static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800115 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800116 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800117}
118
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000119static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800120 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
121 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800122 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800123}
124
Chong Zhang47e36a32016-02-29 16:44:33 -0800125static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
126 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
127 if (ctrl != NULL) {
128 ctrl->disconnect();
129 }
130}
131
Robert Carr6486d312017-01-09 19:48:29 -0800132static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
133 int left = env->GetIntField(rectObj, gRectClassInfo.left);
134 int top = env->GetIntField(rectObj, gRectClassInfo.top);
135 int right = env->GetIntField(rectObj, gRectClassInfo.right);
136 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
137 return Rect(left, top, right, bottom);
138}
139
140static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
141 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
142 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
143 int rotation) {
144 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
145 if (displayToken == NULL) {
146 return NULL;
147 }
148 Rect sourceCrop = rectFromObj(env, sourceCropObj);
149 if (allLayers) {
150 minLayer = 0;
151 maxLayer = -1;
152 }
153 sp<GraphicBuffer> buffer;
154 status_t res = ScreenshotClient::captureToBuffer(displayToken,
155 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
156 rotation, &buffer);
157 if (res != NO_ERROR) {
158 return NULL;
159 }
160
161 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
162 gGraphicBufferClassInfo.builder,
163 buffer->getWidth(),
164 buffer->getHeight(),
165 buffer->getPixelFormat(),
166 buffer->getUsage(),
167 (void*)buffer.get());
168}
169
Dan Stoza9890e3412014-05-22 16:12:54 -0700170static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
171 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700172 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
173 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800174 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
175 if (displayToken == NULL) {
176 return NULL;
177 }
178
Robert Carr6486d312017-01-09 19:48:29 -0800179 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700180
Ben Wagner60126ef2015-08-07 12:13:48 -0400181 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500182 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700183 if (allLayers) {
184 minLayer = 0;
Andreas Gampe0f0b4912014-11-12 08:03:48 -0800185 maxLayer = -1;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500186 }
Riley Andrews1d134062014-08-21 15:47:07 -0700187
188 res = screenshot->update(displayToken, sourceCrop, width, height,
189 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500190 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800191 return NULL;
192 }
193
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400194 SkColorType colorType;
195 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500196 switch (screenshot->getFormat()) {
197 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400198 colorType = kRGBA_8888_SkColorType;
199 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500200 break;
201 }
202 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400203 colorType = kRGBA_8888_SkColorType;
204 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500205 break;
206 }
Romain Guy9505a652016-12-14 09:43:50 -0800207 case PIXEL_FORMAT_RGBA_FP16: {
208 colorType = kRGBA_F16_SkColorType;
209 alphaType = kPremul_SkAlphaType;
210 break;
211 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500212 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400213 colorType = kRGB_565_SkColorType;
214 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500215 break;
216 }
217 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500218 return NULL;
219 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800220 }
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400221 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
222 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700223 colorType,
224 alphaType,
225 GraphicsJNI::defaultColorSpace());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800226
John Reckf29ed282015-04-07 07:32:03 -0700227 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500228 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
229
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400230 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700231 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800232 }
233
sergeyvc1c54062016-10-19 18:47:26 -0700234 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700235 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
236 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400237 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700238 bitmap->setImmutable();
239 return bitmap::createBitmap(env, bitmap,
240 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800241}
242
Dan Stoza9890e3412014-05-22 16:12:54 -0700243static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
244 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
245 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800246 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
247 if (displayToken != NULL) {
248 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
249 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700250 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
251 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
252 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
253 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
254 Rect sourceCrop(left, top, right, bottom);
255
Mathias Agopian0449a402013-03-01 23:01:51 -0800256 if (allLayers) {
257 minLayer = 0;
258 maxLayer = -1;
259 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700260 ScreenshotClient::capture(displayToken,
261 consumer->getIGraphicBufferProducer(), sourceCrop,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800262 width, height, uint32_t(minLayer), uint32_t(maxLayer),
263 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800264 }
265 }
266}
267
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800268static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
269 SurfaceComposerClient::openGlobalTransaction();
270}
271
Robert Carre9953b12016-05-23 20:52:04 -0700272
273static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
274 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800275}
276
277static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
278 SurfaceComposerClient::setAnimationTransaction();
279}
280
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000281static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800282 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
283 status_t err = ctrl->setLayer(zorder);
284 if (err < 0 && err != NO_INIT) {
285 doThrowIAE(env);
286 }
287}
288
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000289static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800290 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
291 status_t err = ctrl->setPosition(x, y);
292 if (err < 0 && err != NO_INIT) {
293 doThrowIAE(env);
294 }
295}
296
Robert Carr6da3cc02016-06-16 15:17:07 -0700297static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700298 jlong nativeObject) {
299 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700300 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700301 if (err < 0 && err != NO_INIT) {
302 doThrowIAE(env);
303 }
304}
305
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000306static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800307 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
308 status_t err = ctrl->setSize(w, h);
309 if (err < 0 && err != NO_INIT) {
310 doThrowIAE(env);
311 }
312}
313
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000314static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800315 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
316 status_t err = ctrl->setFlags(flags, mask);
317 if (err < 0 && err != NO_INIT) {
318 doThrowIAE(env);
319 }
320}
321
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000322static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800323 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
324 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
325 if (!region) {
326 doThrowIAE(env);
327 return;
328 }
329
330 const SkIRect& b(region->getBounds());
331 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
332 if (region->isComplex()) {
333 SkRegion::Iterator it(*region);
334 while (!it.done()) {
335 const SkIRect& r(it.rect());
336 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
337 it.next();
338 }
339 }
340
341 status_t err = ctrl->setTransparentRegionHint(reg);
342 if (err < 0 && err != NO_INIT) {
343 doThrowIAE(env);
344 }
345}
346
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000347static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800348 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
349 status_t err = ctrl->setAlpha(alpha);
350 if (err < 0 && err != NO_INIT) {
351 doThrowIAE(env);
352 }
353}
354
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000355static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800356 jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
357 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
358 status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
359 if (err < 0 && err != NO_INIT) {
360 doThrowIAE(env);
361 }
362}
363
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000364static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800365 jint l, jint t, jint r, jint b) {
366 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
367 Rect crop(l, t, r, b);
368 status_t err = ctrl->setCrop(crop);
369 if (err < 0 && err != NO_INIT) {
370 doThrowIAE(env);
371 }
372}
373
Pablo Ceballos27982e62016-03-09 10:50:45 -0800374static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
375 jint l, jint t, jint r, jint b) {
376 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
377 Rect crop(l, t, r, b);
378 status_t err = ctrl->setFinalCrop(crop);
379 if (err < 0 && err != NO_INIT) {
380 doThrowIAE(env);
381 }
382}
383
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000384static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800385 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
386 status_t err = ctrl->setLayerStack(layerStack);
387 if (err < 0 && err != NO_INIT) {
388 doThrowIAE(env);
389 }
390}
391
392static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
393 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
394 return javaObjectForIBinder(env, token);
395}
396
397static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
398 jboolean secure) {
399 ScopedUtfChars name(env, nameObj);
400 sp<IBinder> token(SurfaceComposerClient::createDisplay(
401 String8(name.c_str()), bool(secure)));
402 return javaObjectForIBinder(env, token);
403}
404
Jesse Hall6a6bc212013-08-08 12:15:03 -0700405static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
406 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
407 if (token == NULL) return;
408 SurfaceComposerClient::destroyDisplay(token);
409}
410
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800411static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000412 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800413 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
414 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800415 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800416 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800417 if (sur != NULL) {
418 bufferProducer = sur->getIGraphicBufferProducer();
419 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700420 status_t err = SurfaceComposerClient::setDisplaySurface(token,
421 bufferProducer);
422 if (err != NO_ERROR) {
423 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
424 " Surface created with singleBufferMode?");
425 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800426}
427
428static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
429 jobject tokenObj, jint layerStack) {
430 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
431 if (token == NULL) return;
432
433 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
434}
435
436static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
437 jobject tokenObj, jint orientation,
438 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
439 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
440 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
441 if (token == NULL) return;
442 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
443 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
444 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
445}
446
Michael Wright01e840f2014-06-26 16:03:25 -0700447static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
448 jobject tokenObj, jint width, jint height) {
449 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
450 if (token == NULL) return;
451 SurfaceComposerClient::setDisplaySize(token, width, height);
452}
453
Dan Stoza00101052014-05-02 15:23:40 -0700454static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
455 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800456 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700457 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800458
Dan Stoza00101052014-05-02 15:23:40 -0700459 Vector<DisplayInfo> configs;
460 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
461 configs.size() == 0) {
462 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800463 }
464
Dan Stoza00101052014-05-02 15:23:40 -0700465 jobjectArray configArray = env->NewObjectArray(configs.size(),
466 gPhysicalDisplayInfoClassInfo.clazz, NULL);
467
468 for (size_t c = 0; c < configs.size(); ++c) {
469 const DisplayInfo& info = configs[c];
470 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
471 gPhysicalDisplayInfoClassInfo.ctor);
472 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
473 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
474 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
475 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
476 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
477 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
478 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700479 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
480 info.appVsyncOffset);
481 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
482 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700483 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
484 env->DeleteLocalRef(infoObj);
485 }
486
487 return configArray;
488}
489
490static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
491 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
492 if (token == NULL) return -1;
493 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
494}
495
496static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
497 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
498 if (token == NULL) return JNI_FALSE;
499 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
500 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800501}
502
Michael Wright1c9977b2016-07-12 13:30:10 -0700503static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
504 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
505 if (token == NULL) return NULL;
506 Vector<android_color_mode_t> colorModes;
507 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
508 colorModes.isEmpty()) {
509 return NULL;
510 }
511
512 jintArray colorModesArray = env->NewIntArray(colorModes.size());
513 if (colorModesArray == NULL) {
514 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
515 return NULL;
516 }
517 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
518 for (size_t i = 0; i < colorModes.size(); i++) {
519 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
520 }
521 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
522 return colorModesArray;
523}
524
525static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
526 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
527 if (token == NULL) return -1;
528 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
529}
530
531static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
532 jobject tokenObj, jint colorMode) {
533 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
534 if (token == NULL) return JNI_FALSE;
535 status_t err = SurfaceComposerClient::setActiveColorMode(token,
536 static_cast<android_color_mode_t>(colorMode));
537 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
538}
539
Prashant Malanic55929a2014-05-25 01:59:21 -0700540static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800541 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
542 if (token == NULL) return;
543
Prashant Malanic55929a2014-05-25 01:59:21 -0700544 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
545 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800546}
547
Svetoslav1376d602014-03-13 11:17:26 -0700548static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
549 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
550 status_t err = ctrl->clearLayerFrameStats();
551
552 if (err < 0 && err != NO_INIT) {
553 doThrowIAE(env);
554 }
555
556 // The other end is not ready, just report we failed.
557 if (err == NO_INIT) {
558 return JNI_FALSE;
559 }
560
561 return JNI_TRUE;
562}
563
564static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
565 jobject outStats) {
566 FrameStats stats;
567
568 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
569 status_t err = ctrl->getLayerFrameStats(&stats);
570 if (err < 0 && err != NO_INIT) {
571 doThrowIAE(env);
572 }
573
574 // The other end is not ready, fine just return empty stats.
575 if (err == NO_INIT) {
576 return JNI_FALSE;
577 }
578
579 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
580 size_t frameCount = stats.desiredPresentTimesNano.size();
581
582 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
583 if (postedTimesNanoDst == NULL) {
584 return JNI_FALSE;
585 }
586
587 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
588 if (presentedTimesNanoDst == NULL) {
589 return JNI_FALSE;
590 }
591
592 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
593 if (readyTimesNanoDst == NULL) {
594 return JNI_FALSE;
595 }
596
597 nsecs_t postedTimesNanoSrc[frameCount];
598 nsecs_t presentedTimesNanoSrc[frameCount];
599 nsecs_t readyTimesNanoSrc[frameCount];
600
601 for (size_t i = 0; i < frameCount; i++) {
602 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
603 if (postedTimeNano == INT64_MAX) {
604 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
605 }
606 postedTimesNanoSrc[i] = postedTimeNano;
607
608 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
609 if (presentedTimeNano == INT64_MAX) {
610 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
611 }
612 presentedTimesNanoSrc[i] = presentedTimeNano;
613
614 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
615 if (readyTimeNano == INT64_MAX) {
616 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
617 }
618 readyTimesNanoSrc[i] = readyTimeNano;
619 }
620
621 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
622 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
623 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
624
625 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
626 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
627
628 if (env->ExceptionCheck()) {
629 return JNI_FALSE;
630 }
631
632 return JNI_TRUE;
633}
634
635static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
636 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
637
638 if (err < 0 && err != NO_INIT) {
639 doThrowIAE(env);
640 }
641
642 // The other end is not ready, just report we failed.
643 if (err == NO_INIT) {
644 return JNI_FALSE;
645 }
646
647 return JNI_TRUE;
648}
649
650static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
651 FrameStats stats;
652
653 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
654 if (err < 0 && err != NO_INIT) {
655 doThrowIAE(env);
656 }
657
658 // The other end is not ready, fine just return empty stats.
659 if (err == NO_INIT) {
660 return JNI_FALSE;
661 }
662
663 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
664 size_t frameCount = stats.desiredPresentTimesNano.size();
665
666 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
667 if (presentedTimesNanoDst == NULL) {
668 return JNI_FALSE;
669 }
670
671 nsecs_t presentedTimesNanoSrc[frameCount];
672
673 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700674 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700675 if (presentedTimeNano == INT64_MAX) {
676 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
677 }
678 presentedTimesNanoSrc[i] = presentedTimeNano;
679 }
680
681 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
682
683 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
684 presentedTimesNanoDst);
685
686 if (env->ExceptionCheck()) {
687 return JNI_FALSE;
688 }
689
690 return JNI_TRUE;
691}
692
Rob Carr64e516f2015-10-29 00:20:45 +0000693
694static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
695 jobject handleObject, jlong frameNumber) {
696 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
697 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
698
699 ctrl->deferTransactionUntil(handle, frameNumber);
700}
701
Robert Carr1ca6a332016-04-11 18:00:43 -0700702static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
703 jint scalingMode) {
704 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
705
706 ctrl->setOverrideScalingMode(scalingMode);
707}
708
Rob Carr64e516f2015-10-29 00:20:45 +0000709static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
710 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
711
712 return javaObjectForIBinder(env, ctrl->getHandle());
713}
714
Robert Carr6da3cc02016-06-16 15:17:07 -0700715static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) {
716 bool out = false;
717 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
718 status_t status = ctrl->getTransformToDisplayInverse(&out);
719 if (status != NO_ERROR) {
720 return false;
721 }
722 return out;
723}
724
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700725static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
726 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
727 if (token == NULL) return NULL;
728
729 HdrCapabilities capabilities;
730 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
731
732 const auto& types = capabilities.getSupportedHdrTypes();
733 auto typesArray = env->NewIntArray(types.size());
734 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
735
Michael Wright9ff94c02016-03-30 18:05:40 -0700736 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700737 typesArray, capabilities.getDesiredMaxLuminance(),
738 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
739}
740
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800741// ----------------------------------------------------------------------------
742
Daniel Micay76f6a862015-09-19 17:31:01 -0400743static const JNINativeMethod sSurfaceControlMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000744 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800745 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000746 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800747 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000748 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800749 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800750 {"nativeDisconnect", "(J)V",
751 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700752 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800753 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700754 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800755 (void*)nativeScreenshot },
756 {"nativeOpenTransaction", "()V",
757 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700758 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800759 (void*)nativeCloseTransaction },
760 {"nativeSetAnimationTransaction", "()V",
761 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000762 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800763 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000764 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800765 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700766 {"nativeSetGeometryAppliesWithResize", "(J)V",
767 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000768 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800769 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000770 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800771 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000772 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800773 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000774 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800775 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000776 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800777 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000778 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800779 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800780 {"nativeSetFinalCrop", "(JIIII)V",
781 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000782 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800783 (void*)nativeSetLayerStack },
784 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
785 (void*)nativeGetBuiltInDisplay },
786 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
787 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700788 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
789 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000790 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800791 (void*)nativeSetDisplaySurface },
792 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
793 (void*)nativeSetDisplayLayerStack },
794 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
795 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700796 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
797 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700798 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
799 (void*)nativeGetDisplayConfigs },
800 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
801 (void*)nativeGetActiveConfig },
802 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
803 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700804 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
805 (void*)nativeGetDisplayColorModes},
806 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
807 (void*)nativeGetActiveColorMode},
808 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
809 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700810 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
811 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700812 {"nativeClearContentFrameStats", "(J)Z",
813 (void*)nativeClearContentFrameStats },
814 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
815 (void*)nativeGetContentFrameStats },
816 {"nativeClearAnimationFrameStats", "()Z",
817 (void*)nativeClearAnimationFrameStats },
818 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
819 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700820 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
821 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000822 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
823 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700824 {"nativeSetOverrideScalingMode", "(JI)V",
825 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000826 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700827 (void*)nativeGetHandle },
828 {"nativeGetTransformToDisplayInverse", "(J)Z",
Robert Carr6486d312017-01-09 19:48:29 -0800829 (void*)nativeGetTransformToDisplayInverse },
830 {"nativeScreenshotToBuffer",
831 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
832 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800833};
834
835int register_android_view_SurfaceControl(JNIEnv* env)
836{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800837 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800838 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
839
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800840 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
841 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
842 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
843 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
844 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
845 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
846 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
847 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
848 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
849 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
850 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
851 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
852 clazz, "appVsyncOffsetNanos", "J");
853 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
854 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700855
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800856 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
857 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
858 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
859 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
860 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700861
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800862 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
863 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
864 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700865 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
866
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800867 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
868 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
869 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700870 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
871
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800872 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
873 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
874 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700875 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
876
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700877 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
878 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
879 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
880 "([IFFF)V");
881
Robert Carr6486d312017-01-09 19:48:29 -0800882 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
883 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
884 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
885 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
886
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800887 return err;
888}
889
890};