blob: fa1313bfd79dbfc9531f4442232632c7c88cf265 [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>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080035#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070036#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070037#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038#include <ui/Rect.h>
39#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080040#include <utils/Log.h>
41
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042// ----------------------------------------------------------------------------
43
44namespace android {
45
46static const char* const OutOfResourcesException =
47 "android/view/Surface$OutOfResourcesException";
48
49static struct {
Dan Stoza00101052014-05-02 15:23:40 -070050 jclass clazz;
51 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080052 jfieldID width;
53 jfieldID height;
54 jfieldID refreshRate;
55 jfieldID density;
56 jfieldID xDpi;
57 jfieldID yDpi;
58 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070059 jfieldID appVsyncOffsetNanos;
60 jfieldID presentationDeadlineNanos;
Dan Stoza904f4852015-08-31 12:01:48 -070061 jfieldID colorTransform;
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 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800374 SurfaceComposerClient::setDisplaySurface(token, bufferProducer);
375}
376
377static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
378 jobject tokenObj, jint layerStack) {
379 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
380 if (token == NULL) return;
381
382 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
383}
384
385static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
386 jobject tokenObj, jint orientation,
387 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
388 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
389 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
390 if (token == NULL) return;
391 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
392 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
393 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
394}
395
Michael Wright01e840f2014-06-26 16:03:25 -0700396static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
397 jobject tokenObj, jint width, jint height) {
398 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
399 if (token == NULL) return;
400 SurfaceComposerClient::setDisplaySize(token, width, height);
401}
402
Dan Stoza00101052014-05-02 15:23:40 -0700403static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
404 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800405 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700406 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800407
Dan Stoza00101052014-05-02 15:23:40 -0700408 Vector<DisplayInfo> configs;
409 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
410 configs.size() == 0) {
411 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412 }
413
Dan Stoza00101052014-05-02 15:23:40 -0700414 jobjectArray configArray = env->NewObjectArray(configs.size(),
415 gPhysicalDisplayInfoClassInfo.clazz, NULL);
416
417 for (size_t c = 0; c < configs.size(); ++c) {
418 const DisplayInfo& info = configs[c];
419 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
420 gPhysicalDisplayInfoClassInfo.ctor);
421 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
422 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
423 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
424 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
425 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
426 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
427 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700428 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
429 info.appVsyncOffset);
430 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
431 info.presentationDeadline);
Dan Stoza904f4852015-08-31 12:01:48 -0700432 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.colorTransform,
433 info.colorTransform);
Dan Stoza00101052014-05-02 15:23:40 -0700434 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
435 env->DeleteLocalRef(infoObj);
436 }
437
438 return configArray;
439}
440
441static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
442 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
443 if (token == NULL) return -1;
444 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
445}
446
447static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
448 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
449 if (token == NULL) return JNI_FALSE;
450 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
451 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800452}
453
Prashant Malanic55929a2014-05-25 01:59:21 -0700454static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800455 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
456 if (token == NULL) return;
457
Prashant Malanic55929a2014-05-25 01:59:21 -0700458 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
459 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800460}
461
Svetoslav1376d602014-03-13 11:17:26 -0700462static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
463 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
464 status_t err = ctrl->clearLayerFrameStats();
465
466 if (err < 0 && err != NO_INIT) {
467 doThrowIAE(env);
468 }
469
470 // The other end is not ready, just report we failed.
471 if (err == NO_INIT) {
472 return JNI_FALSE;
473 }
474
475 return JNI_TRUE;
476}
477
478static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
479 jobject outStats) {
480 FrameStats stats;
481
482 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
483 status_t err = ctrl->getLayerFrameStats(&stats);
484 if (err < 0 && err != NO_INIT) {
485 doThrowIAE(env);
486 }
487
488 // The other end is not ready, fine just return empty stats.
489 if (err == NO_INIT) {
490 return JNI_FALSE;
491 }
492
493 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
494 size_t frameCount = stats.desiredPresentTimesNano.size();
495
496 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
497 if (postedTimesNanoDst == NULL) {
498 return JNI_FALSE;
499 }
500
501 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
502 if (presentedTimesNanoDst == NULL) {
503 return JNI_FALSE;
504 }
505
506 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
507 if (readyTimesNanoDst == NULL) {
508 return JNI_FALSE;
509 }
510
511 nsecs_t postedTimesNanoSrc[frameCount];
512 nsecs_t presentedTimesNanoSrc[frameCount];
513 nsecs_t readyTimesNanoSrc[frameCount];
514
515 for (size_t i = 0; i < frameCount; i++) {
516 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
517 if (postedTimeNano == INT64_MAX) {
518 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
519 }
520 postedTimesNanoSrc[i] = postedTimeNano;
521
522 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
523 if (presentedTimeNano == INT64_MAX) {
524 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
525 }
526 presentedTimesNanoSrc[i] = presentedTimeNano;
527
528 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
529 if (readyTimeNano == INT64_MAX) {
530 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
531 }
532 readyTimesNanoSrc[i] = readyTimeNano;
533 }
534
535 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
536 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
537 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
538
539 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
540 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
541
542 if (env->ExceptionCheck()) {
543 return JNI_FALSE;
544 }
545
546 return JNI_TRUE;
547}
548
549static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
550 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
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 nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
565 FrameStats stats;
566
567 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
568 if (err < 0 && err != NO_INIT) {
569 doThrowIAE(env);
570 }
571
572 // The other end is not ready, fine just return empty stats.
573 if (err == NO_INIT) {
574 return JNI_FALSE;
575 }
576
577 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
578 size_t frameCount = stats.desiredPresentTimesNano.size();
579
580 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
581 if (presentedTimesNanoDst == NULL) {
582 return JNI_FALSE;
583 }
584
585 nsecs_t presentedTimesNanoSrc[frameCount];
586
587 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700588 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700589 if (presentedTimeNano == INT64_MAX) {
590 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
591 }
592 presentedTimesNanoSrc[i] = presentedTimeNano;
593 }
594
595 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
596
597 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
598 presentedTimesNanoDst);
599
600 if (env->ExceptionCheck()) {
601 return JNI_FALSE;
602 }
603
604 return JNI_TRUE;
605}
606
Rob Carr64e516f2015-10-29 00:20:45 +0000607
608static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
609 jobject handleObject, jlong frameNumber) {
610 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
611 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
612
613 ctrl->deferTransactionUntil(handle, frameNumber);
614}
615
Robert Carr1ca6a332016-04-11 18:00:43 -0700616static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
617 jint scalingMode) {
618 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
619
620 ctrl->setOverrideScalingMode(scalingMode);
621}
622
Rob Carr64e516f2015-10-29 00:20:45 +0000623static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
624 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
625
626 return javaObjectForIBinder(env, ctrl->getHandle());
627}
628
Robert Carr6da3cc02016-06-16 15:17:07 -0700629static jboolean nativeGetTransformToDisplayInverse(JNIEnv* env, jclass clazz, jlong nativeObject) {
630 bool out = false;
631 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
632 status_t status = ctrl->getTransformToDisplayInverse(&out);
633 if (status != NO_ERROR) {
634 return false;
635 }
636 return out;
637}
638
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700639static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
640 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
641 if (token == NULL) return NULL;
642
643 HdrCapabilities capabilities;
644 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
645
646 const auto& types = capabilities.getSupportedHdrTypes();
647 auto typesArray = env->NewIntArray(types.size());
648 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
649
Michael Wright9ff94c02016-03-30 18:05:40 -0700650 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700651 typesArray, capabilities.getDesiredMaxLuminance(),
652 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
653}
654
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800655// ----------------------------------------------------------------------------
656
Daniel Micay76f6a862015-09-19 17:31:01 -0400657static const JNINativeMethod sSurfaceControlMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000658 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800659 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000660 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800661 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000662 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800663 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800664 {"nativeDisconnect", "(J)V",
665 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700666 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800667 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700668 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800669 (void*)nativeScreenshot },
670 {"nativeOpenTransaction", "()V",
671 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700672 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800673 (void*)nativeCloseTransaction },
674 {"nativeSetAnimationTransaction", "()V",
675 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000676 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800677 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000678 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800679 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700680 {"nativeSetGeometryAppliesWithResize", "(J)V",
681 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000682 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800683 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000684 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800685 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000686 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800687 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000688 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800689 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000690 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800691 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000692 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800693 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800694 {"nativeSetFinalCrop", "(JIIII)V",
695 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000696 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800697 (void*)nativeSetLayerStack },
698 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
699 (void*)nativeGetBuiltInDisplay },
700 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
701 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700702 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
703 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000704 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800705 (void*)nativeSetDisplaySurface },
706 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
707 (void*)nativeSetDisplayLayerStack },
708 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
709 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700710 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
711 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700712 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
713 (void*)nativeGetDisplayConfigs },
714 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
715 (void*)nativeGetActiveConfig },
716 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
717 (void*)nativeSetActiveConfig },
Michael Wright9ff94c02016-03-30 18:05:40 -0700718 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
719 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700720 {"nativeClearContentFrameStats", "(J)Z",
721 (void*)nativeClearContentFrameStats },
722 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
723 (void*)nativeGetContentFrameStats },
724 {"nativeClearAnimationFrameStats", "()Z",
725 (void*)nativeClearAnimationFrameStats },
726 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
727 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700728 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
729 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000730 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
731 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700732 {"nativeSetOverrideScalingMode", "(JI)V",
733 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000734 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700735 (void*)nativeGetHandle },
736 {"nativeGetTransformToDisplayInverse", "(J)Z",
737 (void*)nativeGetTransformToDisplayInverse },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800738};
739
740int register_android_view_SurfaceControl(JNIEnv* env)
741{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800742 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800743 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
744
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800745 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
746 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
747 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
748 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
749 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
750 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
751 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
752 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
753 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
754 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
755 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
756 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
757 clazz, "appVsyncOffsetNanos", "J");
758 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
759 clazz, "presentationDeadlineNanos", "J");
Dan Stoza904f4852015-08-31 12:01:48 -0700760 gPhysicalDisplayInfoClassInfo.colorTransform = GetFieldIDOrDie(env, clazz,
761 "colorTransform", "I");
Svetoslav1376d602014-03-13 11:17:26 -0700762
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800763 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
764 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
765 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
766 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
767 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700768
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800769 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
770 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
771 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700772 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
773
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800774 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
775 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
776 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700777 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
778
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800779 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
780 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
781 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700782 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
783
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700784 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
785 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
786 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
787 "([IFFF)V");
788
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800789 return err;
790}
791
792};