blob: 73b3f52f078b9be0a9ff2101ef99f5e2f825cb5e [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(),
178 colorType, alphaType);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800179
John Reckf29ed282015-04-07 07:32:03 -0700180 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500181 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
182
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400183 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700184 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800185 }
186
John Reckf29ed282015-04-07 07:32:03 -0700187 Bitmap* bitmap = new Bitmap(
188 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
189 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400190 screenshot.release();
John Reckae2e8b42015-05-06 14:55:05 -0700191 bitmap->peekAtPixelRef()->setImmutable();
John Reckf29ed282015-04-07 07:32:03 -0700192
Chris Craik1abf5d62013-08-16 12:47:03 -0700193 return GraphicsJNI::createBitmap(env, bitmap,
194 GraphicsJNI::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800195}
196
Dan Stoza9890e3412014-05-22 16:12:54 -0700197static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
198 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
199 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800200 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
201 if (displayToken != NULL) {
202 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
203 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700204 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
205 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
206 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
207 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
208 Rect sourceCrop(left, top, right, bottom);
209
Mathias Agopian0449a402013-03-01 23:01:51 -0800210 if (allLayers) {
211 minLayer = 0;
212 maxLayer = -1;
213 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700214 ScreenshotClient::capture(displayToken,
215 consumer->getIGraphicBufferProducer(), sourceCrop,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800216 width, height, uint32_t(minLayer), uint32_t(maxLayer),
217 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800218 }
219 }
220}
221
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800222static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
223 SurfaceComposerClient::openGlobalTransaction();
224}
225
Robert Carre9953b12016-05-23 20:52:04 -0700226
227static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
228 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800229}
230
231static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
232 SurfaceComposerClient::setAnimationTransaction();
233}
234
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000235static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800236 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
237 status_t err = ctrl->setLayer(zorder);
238 if (err < 0 && err != NO_INIT) {
239 doThrowIAE(env);
240 }
241}
242
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000243static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800244 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
245 status_t err = ctrl->setPosition(x, y);
246 if (err < 0 && err != NO_INIT) {
247 doThrowIAE(env);
248 }
249}
250
Robert Carr6da3cc02016-06-16 15:17:07 -0700251static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700252 jlong nativeObject) {
253 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700254 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700255 if (err < 0 && err != NO_INIT) {
256 doThrowIAE(env);
257 }
258}
259
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000260static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800261 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
262 status_t err = ctrl->setSize(w, h);
263 if (err < 0 && err != NO_INIT) {
264 doThrowIAE(env);
265 }
266}
267
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000268static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800269 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
270 status_t err = ctrl->setFlags(flags, mask);
271 if (err < 0 && err != NO_INIT) {
272 doThrowIAE(env);
273 }
274}
275
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000276static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800277 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
278 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
279 if (!region) {
280 doThrowIAE(env);
281 return;
282 }
283
284 const SkIRect& b(region->getBounds());
285 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
286 if (region->isComplex()) {
287 SkRegion::Iterator it(*region);
288 while (!it.done()) {
289 const SkIRect& r(it.rect());
290 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
291 it.next();
292 }
293 }
294
295 status_t err = ctrl->setTransparentRegionHint(reg);
296 if (err < 0 && err != NO_INIT) {
297 doThrowIAE(env);
298 }
299}
300
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000301static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800302 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
303 status_t err = ctrl->setAlpha(alpha);
304 if (err < 0 && err != NO_INIT) {
305 doThrowIAE(env);
306 }
307}
308
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000309static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800310 jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
311 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
312 status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
313 if (err < 0 && err != NO_INIT) {
314 doThrowIAE(env);
315 }
316}
317
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000318static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800319 jint l, jint t, jint r, jint b) {
320 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
321 Rect crop(l, t, r, b);
322 status_t err = ctrl->setCrop(crop);
323 if (err < 0 && err != NO_INIT) {
324 doThrowIAE(env);
325 }
326}
327
Pablo Ceballos27982e62016-03-09 10:50:45 -0800328static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
329 jint l, jint t, jint r, jint b) {
330 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
331 Rect crop(l, t, r, b);
332 status_t err = ctrl->setFinalCrop(crop);
333 if (err < 0 && err != NO_INIT) {
334 doThrowIAE(env);
335 }
336}
337
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000338static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800339 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
340 status_t err = ctrl->setLayerStack(layerStack);
341 if (err < 0 && err != NO_INIT) {
342 doThrowIAE(env);
343 }
344}
345
346static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
347 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
348 return javaObjectForIBinder(env, token);
349}
350
351static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
352 jboolean secure) {
353 ScopedUtfChars name(env, nameObj);
354 sp<IBinder> token(SurfaceComposerClient::createDisplay(
355 String8(name.c_str()), bool(secure)));
356 return javaObjectForIBinder(env, token);
357}
358
Jesse Hall6a6bc212013-08-08 12:15:03 -0700359static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
360 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
361 if (token == NULL) return;
362 SurfaceComposerClient::destroyDisplay(token);
363}
364
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800365static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000366 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800367 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
368 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800369 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800370 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800371 if (sur != NULL) {
372 bufferProducer = sur->getIGraphicBufferProducer();
373 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700374 status_t err = SurfaceComposerClient::setDisplaySurface(token,
375 bufferProducer);
376 if (err != NO_ERROR) {
377 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
378 " Surface created with singleBufferMode?");
379 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800380}
381
382static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
383 jobject tokenObj, jint layerStack) {
384 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
385 if (token == NULL) return;
386
387 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
388}
389
390static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
391 jobject tokenObj, jint orientation,
392 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
393 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
394 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
395 if (token == NULL) return;
396 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
397 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
398 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
399}
400
Michael Wright01e840f2014-06-26 16:03:25 -0700401static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
402 jobject tokenObj, jint width, jint height) {
403 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
404 if (token == NULL) return;
405 SurfaceComposerClient::setDisplaySize(token, width, height);
406}
407
Dan Stoza00101052014-05-02 15:23:40 -0700408static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
409 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800410 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700411 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412
Dan Stoza00101052014-05-02 15:23:40 -0700413 Vector<DisplayInfo> configs;
414 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
415 configs.size() == 0) {
416 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800417 }
418
Dan Stoza00101052014-05-02 15:23:40 -0700419 jobjectArray configArray = env->NewObjectArray(configs.size(),
420 gPhysicalDisplayInfoClassInfo.clazz, NULL);
421
422 for (size_t c = 0; c < configs.size(); ++c) {
423 const DisplayInfo& info = configs[c];
424 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
425 gPhysicalDisplayInfoClassInfo.ctor);
426 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
427 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
428 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
429 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
430 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
431 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
432 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700433 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
434 info.appVsyncOffset);
435 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
436 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700437 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
438 env->DeleteLocalRef(infoObj);
439 }
440
441 return configArray;
442}
443
444static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
445 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
446 if (token == NULL) return -1;
447 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
448}
449
450static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
451 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
452 if (token == NULL) return JNI_FALSE;
453 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
454 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800455}
456
Michael Wright1c9977b2016-07-12 13:30:10 -0700457static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
458 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
459 if (token == NULL) return NULL;
460 Vector<android_color_mode_t> colorModes;
461 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
462 colorModes.isEmpty()) {
463 return NULL;
464 }
465
466 jintArray colorModesArray = env->NewIntArray(colorModes.size());
467 if (colorModesArray == NULL) {
468 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
469 return NULL;
470 }
471 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
472 for (size_t i = 0; i < colorModes.size(); i++) {
473 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
474 }
475 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
476 return colorModesArray;
477}
478
479static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
480 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
481 if (token == NULL) return -1;
482 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
483}
484
485static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
486 jobject tokenObj, jint colorMode) {
487 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
488 if (token == NULL) return JNI_FALSE;
489 status_t err = SurfaceComposerClient::setActiveColorMode(token,
490 static_cast<android_color_mode_t>(colorMode));
491 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
492}
493
Prashant Malanic55929a2014-05-25 01:59:21 -0700494static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800495 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
496 if (token == NULL) return;
497
Prashant Malanic55929a2014-05-25 01:59:21 -0700498 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
499 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800500}
501
Svetoslav1376d602014-03-13 11:17:26 -0700502static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
503 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
504 status_t err = ctrl->clearLayerFrameStats();
505
506 if (err < 0 && err != NO_INIT) {
507 doThrowIAE(env);
508 }
509
510 // The other end is not ready, just report we failed.
511 if (err == NO_INIT) {
512 return JNI_FALSE;
513 }
514
515 return JNI_TRUE;
516}
517
518static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
519 jobject outStats) {
520 FrameStats stats;
521
522 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
523 status_t err = ctrl->getLayerFrameStats(&stats);
524 if (err < 0 && err != NO_INIT) {
525 doThrowIAE(env);
526 }
527
528 // The other end is not ready, fine just return empty stats.
529 if (err == NO_INIT) {
530 return JNI_FALSE;
531 }
532
533 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
534 size_t frameCount = stats.desiredPresentTimesNano.size();
535
536 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
537 if (postedTimesNanoDst == NULL) {
538 return JNI_FALSE;
539 }
540
541 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
542 if (presentedTimesNanoDst == NULL) {
543 return JNI_FALSE;
544 }
545
546 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
547 if (readyTimesNanoDst == NULL) {
548 return JNI_FALSE;
549 }
550
551 nsecs_t postedTimesNanoSrc[frameCount];
552 nsecs_t presentedTimesNanoSrc[frameCount];
553 nsecs_t readyTimesNanoSrc[frameCount];
554
555 for (size_t i = 0; i < frameCount; i++) {
556 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
557 if (postedTimeNano == INT64_MAX) {
558 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
559 }
560 postedTimesNanoSrc[i] = postedTimeNano;
561
562 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
563 if (presentedTimeNano == INT64_MAX) {
564 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
565 }
566 presentedTimesNanoSrc[i] = presentedTimeNano;
567
568 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
569 if (readyTimeNano == INT64_MAX) {
570 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
571 }
572 readyTimesNanoSrc[i] = readyTimeNano;
573 }
574
575 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
576 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
577 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
578
579 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
580 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
581
582 if (env->ExceptionCheck()) {
583 return JNI_FALSE;
584 }
585
586 return JNI_TRUE;
587}
588
589static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
590 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
591
592 if (err < 0 && err != NO_INIT) {
593 doThrowIAE(env);
594 }
595
596 // The other end is not ready, just report we failed.
597 if (err == NO_INIT) {
598 return JNI_FALSE;
599 }
600
601 return JNI_TRUE;
602}
603
604static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
605 FrameStats stats;
606
607 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
608 if (err < 0 && err != NO_INIT) {
609 doThrowIAE(env);
610 }
611
612 // The other end is not ready, fine just return empty stats.
613 if (err == NO_INIT) {
614 return JNI_FALSE;
615 }
616
617 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
618 size_t frameCount = stats.desiredPresentTimesNano.size();
619
620 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
621 if (presentedTimesNanoDst == NULL) {
622 return JNI_FALSE;
623 }
624
625 nsecs_t presentedTimesNanoSrc[frameCount];
626
627 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700628 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700629 if (presentedTimeNano == INT64_MAX) {
630 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
631 }
632 presentedTimesNanoSrc[i] = presentedTimeNano;
633 }
634
635 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
636
637 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
638 presentedTimesNanoDst);
639
640 if (env->ExceptionCheck()) {
641 return JNI_FALSE;
642 }
643
644 return JNI_TRUE;
645}
646
Rob Carr64e516f2015-10-29 00:20:45 +0000647
648static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
649 jobject handleObject, jlong frameNumber) {
650 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
651 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
652
653 ctrl->deferTransactionUntil(handle, frameNumber);
654}
655
Robert Carr1ca6a332016-04-11 18:00:43 -0700656static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
657 jint scalingMode) {
658 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
659
660 ctrl->setOverrideScalingMode(scalingMode);
661}
662
Rob Carr64e516f2015-10-29 00:20:45 +0000663static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
664 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
665
666 return javaObjectForIBinder(env, ctrl->getHandle());
667}
668
Robert Carr6da3cc02016-06-16 15:17:07 -0700669static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) {
670 bool out = false;
671 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
672 status_t status = ctrl->getTransformToDisplayInverse(&out);
673 if (status != NO_ERROR) {
674 return false;
675 }
676 return out;
677}
678
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700679static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
680 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
681 if (token == NULL) return NULL;
682
683 HdrCapabilities capabilities;
684 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
685
686 const auto& types = capabilities.getSupportedHdrTypes();
687 auto typesArray = env->NewIntArray(types.size());
688 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
689
Michael Wright9ff94c02016-03-30 18:05:40 -0700690 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700691 typesArray, capabilities.getDesiredMaxLuminance(),
692 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
693}
694
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800695// ----------------------------------------------------------------------------
696
Daniel Micay76f6a862015-09-19 17:31:01 -0400697static const JNINativeMethod sSurfaceControlMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000698 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800699 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000700 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800701 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000702 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800703 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800704 {"nativeDisconnect", "(J)V",
705 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700706 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800707 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700708 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800709 (void*)nativeScreenshot },
710 {"nativeOpenTransaction", "()V",
711 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700712 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800713 (void*)nativeCloseTransaction },
714 {"nativeSetAnimationTransaction", "()V",
715 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000716 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800717 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000718 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800719 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700720 {"nativeSetGeometryAppliesWithResize", "(J)V",
721 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000722 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800723 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000724 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800725 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000726 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800727 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000728 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800729 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000730 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800731 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000732 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800733 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800734 {"nativeSetFinalCrop", "(JIIII)V",
735 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000736 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800737 (void*)nativeSetLayerStack },
738 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
739 (void*)nativeGetBuiltInDisplay },
740 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
741 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700742 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
743 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000744 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800745 (void*)nativeSetDisplaySurface },
746 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
747 (void*)nativeSetDisplayLayerStack },
748 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
749 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700750 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
751 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700752 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
753 (void*)nativeGetDisplayConfigs },
754 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
755 (void*)nativeGetActiveConfig },
756 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
757 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700758 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
759 (void*)nativeGetDisplayColorModes},
760 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
761 (void*)nativeGetActiveColorMode},
762 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
763 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700764 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
765 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700766 {"nativeClearContentFrameStats", "(J)Z",
767 (void*)nativeClearContentFrameStats },
768 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
769 (void*)nativeGetContentFrameStats },
770 {"nativeClearAnimationFrameStats", "()Z",
771 (void*)nativeClearAnimationFrameStats },
772 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
773 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700774 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
775 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000776 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
777 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700778 {"nativeSetOverrideScalingMode", "(JI)V",
779 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000780 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700781 (void*)nativeGetHandle },
782 {"nativeGetTransformToDisplayInverse", "(J)Z",
783 (void*)nativeGetTransformToDisplayInverse },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800784};
785
786int register_android_view_SurfaceControl(JNIEnv* env)
787{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800788 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800789 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
790
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800791 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
792 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
793 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
794 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
795 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
796 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
797 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
798 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
799 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
800 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
801 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
802 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
803 clazz, "appVsyncOffsetNanos", "J");
804 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
805 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700806
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800807 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
808 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
809 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
810 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
811 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700812
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800813 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
814 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
815 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700816 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
817
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800818 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
819 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
820 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700821 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
822
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800823 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
824 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
825 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700826 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
827
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700828 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
829 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
830 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
831 "([IFFF)V");
832
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800833 return err;
834}
835
836};