blob: 65f12ac1907a896c655cef6f972d80733ba18fa4 [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"
18
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019#include "android_os_Parcel.h"
20#include "android_util_Binder.h"
John Reckf29ed282015-04-07 07:32:03 -070021#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080022#include "android/graphics/GraphicsJNI.h"
23#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080024#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040025
26#include <JNIHelp.h>
27#include <ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080028#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080029#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080030#include <gui/Surface.h>
31#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040032#include <jni.h>
33#include <memory>
34#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070035#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080036#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070037#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070038#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080039#include <ui/Rect.h>
40#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080041#include <utils/Log.h>
42
Mathias Agopian3866f0d2013-02-11 22:08:48 -080043// ----------------------------------------------------------------------------
44
45namespace android {
46
47static const char* const OutOfResourcesException =
48 "android/view/Surface$OutOfResourcesException";
49
50static struct {
Dan Stoza00101052014-05-02 15:23:40 -070051 jclass clazz;
52 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080053 jfieldID width;
54 jfieldID height;
55 jfieldID refreshRate;
56 jfieldID density;
57 jfieldID xDpi;
58 jfieldID yDpi;
59 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070060 jfieldID appVsyncOffsetNanos;
61 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080062} gPhysicalDisplayInfoClassInfo;
63
Dan Stoza9890e3412014-05-22 16:12:54 -070064static struct {
65 jfieldID bottom;
66 jfieldID left;
67 jfieldID right;
68 jfieldID top;
69} gRectClassInfo;
70
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050071// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
72void DeleteScreenshot(void* addr, void* context) {
73 SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
74 delete ((ScreenshotClient*) context);
75}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080076
Svetoslav1376d602014-03-13 11:17:26 -070077static struct {
78 nsecs_t UNDEFINED_TIME_NANO;
79 jmethodID init;
80} gWindowContentFrameStatsClassInfo;
81
82static struct {
83 nsecs_t UNDEFINED_TIME_NANO;
84 jmethodID init;
85} gWindowAnimationFrameStatsClassInfo;
86
Hangyu Kuang54ac2192016-04-25 13:22:02 -070087static struct {
88 jclass clazz;
89 jmethodID ctor;
90} gHdrCapabilitiesClassInfo;
91
Mathias Agopian3866f0d2013-02-11 22:08:48 -080092// ----------------------------------------------------------------------------
93
Ashok Bhat36bef0b2014-01-20 20:08:01 +000094static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -080095 jstring nameStr, jint w, jint h, jint format, jint flags) {
96 ScopedUtfChars name(env, nameStr);
97 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
98 sp<SurfaceControl> surface = client->createSurface(
99 String8(name.c_str()), w, h, format, flags);
100 if (surface == NULL) {
101 jniThrowException(env, OutOfResourcesException, NULL);
102 return 0;
103 }
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800104 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000105 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800106}
107
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000108static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800109 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800110 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800111}
112
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000113static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800114 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
115 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800116 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800117}
118
Chong Zhang47e36a32016-02-29 16:44:33 -0800119static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
120 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
121 if (ctrl != NULL) {
122 ctrl->disconnect();
123 }
124}
125
Dan Stoza9890e3412014-05-22 16:12:54 -0700126static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
127 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700128 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
129 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800130 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
131 if (displayToken == NULL) {
132 return NULL;
133 }
134
Dan Stoza9890e3412014-05-22 16:12:54 -0700135 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
136 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
137 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
138 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
139 Rect sourceCrop(left, top, right, bottom);
140
Ben Wagner60126ef2015-08-07 12:13:48 -0400141 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500142 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700143 if (allLayers) {
144 minLayer = 0;
Andreas Gampe0f0b4912014-11-12 08:03:48 -0800145 maxLayer = -1;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500146 }
Riley Andrews1d134062014-08-21 15:47:07 -0700147
148 res = screenshot->update(displayToken, sourceCrop, width, height,
149 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500150 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800151 return NULL;
152 }
153
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400154 SkColorType colorType;
155 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500156 switch (screenshot->getFormat()) {
157 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400158 colorType = kRGBA_8888_SkColorType;
159 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500160 break;
161 }
162 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400163 colorType = kRGBA_8888_SkColorType;
164 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500165 break;
166 }
167 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400168 colorType = kRGB_565_SkColorType;
169 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500170 break;
171 }
172 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500173 return NULL;
174 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800175 }
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400176 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
177 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700178 colorType,
179 alphaType,
180 GraphicsJNI::defaultColorSpace());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800181
John Reckf29ed282015-04-07 07:32:03 -0700182 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500183 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
184
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400185 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700186 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800187 }
188
sergeyvc69853c2016-10-07 14:14:09 -0700189 auto pixelRef = new PixelRef(
John Reckf29ed282015-04-07 07:32:03 -0700190 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
191 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400192 screenshot.release();
sergeyvc69853c2016-10-07 14:14:09 -0700193 pixelRef->setImmutable();
John Reckf29ed282015-04-07 07:32:03 -0700194
sergeyvc69853c2016-10-07 14:14:09 -0700195 return bitmap::createBitmap(env, pixelRef,
196 bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800197}
198
Dan Stoza9890e3412014-05-22 16:12:54 -0700199static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
200 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
201 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800202 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
203 if (displayToken != NULL) {
204 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
205 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700206 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
207 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
208 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
209 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
210 Rect sourceCrop(left, top, right, bottom);
211
Mathias Agopian0449a402013-03-01 23:01:51 -0800212 if (allLayers) {
213 minLayer = 0;
214 maxLayer = -1;
215 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700216 ScreenshotClient::capture(displayToken,
217 consumer->getIGraphicBufferProducer(), sourceCrop,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800218 width, height, uint32_t(minLayer), uint32_t(maxLayer),
219 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800220 }
221 }
222}
223
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800224static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
225 SurfaceComposerClient::openGlobalTransaction();
226}
227
Robert Carre9953b12016-05-23 20:52:04 -0700228
229static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
230 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800231}
232
233static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
234 SurfaceComposerClient::setAnimationTransaction();
235}
236
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000237static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800238 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
239 status_t err = ctrl->setLayer(zorder);
240 if (err < 0 && err != NO_INIT) {
241 doThrowIAE(env);
242 }
243}
244
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000245static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800246 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
247 status_t err = ctrl->setPosition(x, y);
248 if (err < 0 && err != NO_INIT) {
249 doThrowIAE(env);
250 }
251}
252
Robert Carr6da3cc02016-06-16 15:17:07 -0700253static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700254 jlong nativeObject) {
255 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700256 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700257 if (err < 0 && err != NO_INIT) {
258 doThrowIAE(env);
259 }
260}
261
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000262static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800263 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
264 status_t err = ctrl->setSize(w, h);
265 if (err < 0 && err != NO_INIT) {
266 doThrowIAE(env);
267 }
268}
269
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000270static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800271 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
272 status_t err = ctrl->setFlags(flags, mask);
273 if (err < 0 && err != NO_INIT) {
274 doThrowIAE(env);
275 }
276}
277
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000278static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800279 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
280 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
281 if (!region) {
282 doThrowIAE(env);
283 return;
284 }
285
286 const SkIRect& b(region->getBounds());
287 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
288 if (region->isComplex()) {
289 SkRegion::Iterator it(*region);
290 while (!it.done()) {
291 const SkIRect& r(it.rect());
292 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
293 it.next();
294 }
295 }
296
297 status_t err = ctrl->setTransparentRegionHint(reg);
298 if (err < 0 && err != NO_INIT) {
299 doThrowIAE(env);
300 }
301}
302
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000303static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800304 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
305 status_t err = ctrl->setAlpha(alpha);
306 if (err < 0 && err != NO_INIT) {
307 doThrowIAE(env);
308 }
309}
310
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000311static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800312 jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
313 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
314 status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
315 if (err < 0 && err != NO_INIT) {
316 doThrowIAE(env);
317 }
318}
319
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000320static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800321 jint l, jint t, jint r, jint b) {
322 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
323 Rect crop(l, t, r, b);
324 status_t err = ctrl->setCrop(crop);
325 if (err < 0 && err != NO_INIT) {
326 doThrowIAE(env);
327 }
328}
329
Pablo Ceballos27982e62016-03-09 10:50:45 -0800330static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
331 jint l, jint t, jint r, jint b) {
332 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
333 Rect crop(l, t, r, b);
334 status_t err = ctrl->setFinalCrop(crop);
335 if (err < 0 && err != NO_INIT) {
336 doThrowIAE(env);
337 }
338}
339
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000340static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800341 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
342 status_t err = ctrl->setLayerStack(layerStack);
343 if (err < 0 && err != NO_INIT) {
344 doThrowIAE(env);
345 }
346}
347
348static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
349 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
350 return javaObjectForIBinder(env, token);
351}
352
353static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
354 jboolean secure) {
355 ScopedUtfChars name(env, nameObj);
356 sp<IBinder> token(SurfaceComposerClient::createDisplay(
357 String8(name.c_str()), bool(secure)));
358 return javaObjectForIBinder(env, token);
359}
360
Jesse Hall6a6bc212013-08-08 12:15:03 -0700361static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
362 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
363 if (token == NULL) return;
364 SurfaceComposerClient::destroyDisplay(token);
365}
366
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800367static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000368 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800369 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
370 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800371 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800372 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800373 if (sur != NULL) {
374 bufferProducer = sur->getIGraphicBufferProducer();
375 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700376 status_t err = SurfaceComposerClient::setDisplaySurface(token,
377 bufferProducer);
378 if (err != NO_ERROR) {
379 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
380 " Surface created with singleBufferMode?");
381 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800382}
383
384static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
385 jobject tokenObj, jint layerStack) {
386 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
387 if (token == NULL) return;
388
389 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
390}
391
392static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
393 jobject tokenObj, jint orientation,
394 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
395 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
396 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
397 if (token == NULL) return;
398 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
399 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
400 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
401}
402
Michael Wright01e840f2014-06-26 16:03:25 -0700403static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
404 jobject tokenObj, jint width, jint height) {
405 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
406 if (token == NULL) return;
407 SurfaceComposerClient::setDisplaySize(token, width, height);
408}
409
Dan Stoza00101052014-05-02 15:23:40 -0700410static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
411 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700413 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414
Dan Stoza00101052014-05-02 15:23:40 -0700415 Vector<DisplayInfo> configs;
416 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
417 configs.size() == 0) {
418 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800419 }
420
Dan Stoza00101052014-05-02 15:23:40 -0700421 jobjectArray configArray = env->NewObjectArray(configs.size(),
422 gPhysicalDisplayInfoClassInfo.clazz, NULL);
423
424 for (size_t c = 0; c < configs.size(); ++c) {
425 const DisplayInfo& info = configs[c];
426 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
427 gPhysicalDisplayInfoClassInfo.ctor);
428 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
429 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
430 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
431 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
432 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
433 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
434 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700435 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
436 info.appVsyncOffset);
437 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
438 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700439 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
440 env->DeleteLocalRef(infoObj);
441 }
442
443 return configArray;
444}
445
446static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
447 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
448 if (token == NULL) return -1;
449 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
450}
451
452static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
453 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
454 if (token == NULL) return JNI_FALSE;
455 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
456 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800457}
458
Michael Wright1c9977b2016-07-12 13:30:10 -0700459static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
460 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
461 if (token == NULL) return NULL;
462 Vector<android_color_mode_t> colorModes;
463 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
464 colorModes.isEmpty()) {
465 return NULL;
466 }
467
468 jintArray colorModesArray = env->NewIntArray(colorModes.size());
469 if (colorModesArray == NULL) {
470 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
471 return NULL;
472 }
473 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
474 for (size_t i = 0; i < colorModes.size(); i++) {
475 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
476 }
477 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
478 return colorModesArray;
479}
480
481static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
482 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
483 if (token == NULL) return -1;
484 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
485}
486
487static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
488 jobject tokenObj, jint colorMode) {
489 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
490 if (token == NULL) return JNI_FALSE;
491 status_t err = SurfaceComposerClient::setActiveColorMode(token,
492 static_cast<android_color_mode_t>(colorMode));
493 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
494}
495
Prashant Malanic55929a2014-05-25 01:59:21 -0700496static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800497 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
498 if (token == NULL) return;
499
Prashant Malanic55929a2014-05-25 01:59:21 -0700500 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
501 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800502}
503
Svetoslav1376d602014-03-13 11:17:26 -0700504static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
505 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
506 status_t err = ctrl->clearLayerFrameStats();
507
508 if (err < 0 && err != NO_INIT) {
509 doThrowIAE(env);
510 }
511
512 // The other end is not ready, just report we failed.
513 if (err == NO_INIT) {
514 return JNI_FALSE;
515 }
516
517 return JNI_TRUE;
518}
519
520static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
521 jobject outStats) {
522 FrameStats stats;
523
524 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
525 status_t err = ctrl->getLayerFrameStats(&stats);
526 if (err < 0 && err != NO_INIT) {
527 doThrowIAE(env);
528 }
529
530 // The other end is not ready, fine just return empty stats.
531 if (err == NO_INIT) {
532 return JNI_FALSE;
533 }
534
535 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
536 size_t frameCount = stats.desiredPresentTimesNano.size();
537
538 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
539 if (postedTimesNanoDst == NULL) {
540 return JNI_FALSE;
541 }
542
543 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
544 if (presentedTimesNanoDst == NULL) {
545 return JNI_FALSE;
546 }
547
548 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
549 if (readyTimesNanoDst == NULL) {
550 return JNI_FALSE;
551 }
552
553 nsecs_t postedTimesNanoSrc[frameCount];
554 nsecs_t presentedTimesNanoSrc[frameCount];
555 nsecs_t readyTimesNanoSrc[frameCount];
556
557 for (size_t i = 0; i < frameCount; i++) {
558 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
559 if (postedTimeNano == INT64_MAX) {
560 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
561 }
562 postedTimesNanoSrc[i] = postedTimeNano;
563
564 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
565 if (presentedTimeNano == INT64_MAX) {
566 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
567 }
568 presentedTimesNanoSrc[i] = presentedTimeNano;
569
570 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
571 if (readyTimeNano == INT64_MAX) {
572 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
573 }
574 readyTimesNanoSrc[i] = readyTimeNano;
575 }
576
577 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
578 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
579 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
580
581 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
582 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
583
584 if (env->ExceptionCheck()) {
585 return JNI_FALSE;
586 }
587
588 return JNI_TRUE;
589}
590
591static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
592 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
593
594 if (err < 0 && err != NO_INIT) {
595 doThrowIAE(env);
596 }
597
598 // The other end is not ready, just report we failed.
599 if (err == NO_INIT) {
600 return JNI_FALSE;
601 }
602
603 return JNI_TRUE;
604}
605
606static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
607 FrameStats stats;
608
609 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
610 if (err < 0 && err != NO_INIT) {
611 doThrowIAE(env);
612 }
613
614 // The other end is not ready, fine just return empty stats.
615 if (err == NO_INIT) {
616 return JNI_FALSE;
617 }
618
619 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
620 size_t frameCount = stats.desiredPresentTimesNano.size();
621
622 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
623 if (presentedTimesNanoDst == NULL) {
624 return JNI_FALSE;
625 }
626
627 nsecs_t presentedTimesNanoSrc[frameCount];
628
629 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700630 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700631 if (presentedTimeNano == INT64_MAX) {
632 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
633 }
634 presentedTimesNanoSrc[i] = presentedTimeNano;
635 }
636
637 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
638
639 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
640 presentedTimesNanoDst);
641
642 if (env->ExceptionCheck()) {
643 return JNI_FALSE;
644 }
645
646 return JNI_TRUE;
647}
648
Rob Carr64e516f2015-10-29 00:20:45 +0000649
650static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
651 jobject handleObject, jlong frameNumber) {
652 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
653 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
654
655 ctrl->deferTransactionUntil(handle, frameNumber);
656}
657
Robert Carr1ca6a332016-04-11 18:00:43 -0700658static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
659 jint scalingMode) {
660 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
661
662 ctrl->setOverrideScalingMode(scalingMode);
663}
664
Rob Carr64e516f2015-10-29 00:20:45 +0000665static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
666 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
667
668 return javaObjectForIBinder(env, ctrl->getHandle());
669}
670
Robert Carr6da3cc02016-06-16 15:17:07 -0700671static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) {
672 bool out = false;
673 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
674 status_t status = ctrl->getTransformToDisplayInverse(&out);
675 if (status != NO_ERROR) {
676 return false;
677 }
678 return out;
679}
680
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700681static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
682 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
683 if (token == NULL) return NULL;
684
685 HdrCapabilities capabilities;
686 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
687
688 const auto& types = capabilities.getSupportedHdrTypes();
689 auto typesArray = env->NewIntArray(types.size());
690 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
691
Michael Wright9ff94c02016-03-30 18:05:40 -0700692 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700693 typesArray, capabilities.getDesiredMaxLuminance(),
694 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
695}
696
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800697// ----------------------------------------------------------------------------
698
Daniel Micay76f6a862015-09-19 17:31:01 -0400699static const JNINativeMethod sSurfaceControlMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000700 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800701 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000702 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800703 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000704 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800705 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800706 {"nativeDisconnect", "(J)V",
707 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700708 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800709 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700710 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800711 (void*)nativeScreenshot },
712 {"nativeOpenTransaction", "()V",
713 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700714 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800715 (void*)nativeCloseTransaction },
716 {"nativeSetAnimationTransaction", "()V",
717 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000718 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800719 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000720 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800721 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700722 {"nativeSetGeometryAppliesWithResize", "(J)V",
723 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000724 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800725 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000726 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800727 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000728 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800729 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000730 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800731 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000732 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800733 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000734 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800735 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800736 {"nativeSetFinalCrop", "(JIIII)V",
737 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000738 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800739 (void*)nativeSetLayerStack },
740 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
741 (void*)nativeGetBuiltInDisplay },
742 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
743 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700744 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
745 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000746 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800747 (void*)nativeSetDisplaySurface },
748 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
749 (void*)nativeSetDisplayLayerStack },
750 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
751 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700752 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
753 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700754 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
755 (void*)nativeGetDisplayConfigs },
756 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
757 (void*)nativeGetActiveConfig },
758 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
759 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700760 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
761 (void*)nativeGetDisplayColorModes},
762 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
763 (void*)nativeGetActiveColorMode},
764 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
765 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700766 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
767 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700768 {"nativeClearContentFrameStats", "(J)Z",
769 (void*)nativeClearContentFrameStats },
770 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
771 (void*)nativeGetContentFrameStats },
772 {"nativeClearAnimationFrameStats", "()Z",
773 (void*)nativeClearAnimationFrameStats },
774 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
775 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700776 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
777 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000778 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
779 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700780 {"nativeSetOverrideScalingMode", "(JI)V",
781 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000782 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700783 (void*)nativeGetHandle },
784 {"nativeGetTransformToDisplayInverse", "(J)Z",
785 (void*)nativeGetTransformToDisplayInverse },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800786};
787
788int register_android_view_SurfaceControl(JNIEnv* env)
789{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800790 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800791 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
792
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800793 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
794 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
795 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
796 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
797 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
798 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
799 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
800 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
801 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
802 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
803 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
804 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
805 clazz, "appVsyncOffsetNanos", "J");
806 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
807 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700808
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800809 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
810 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
811 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
812 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
813 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700814
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800815 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
816 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
817 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700818 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
819
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800820 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
821 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
822 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700823 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
824
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800825 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
826 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
827 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700828 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
829
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700830 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
831 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
832 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
833 "([IFFF)V");
834
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800835 return err;
836}
837
838};