blob: 5df6a2812ce89d937bd53176b5d6b85a4a3aad51 [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceControl"
Robert Carr6486d312017-01-09 19:48:29 -080018#define LOG_NDEBUG 0
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019
Mathias Agopian3866f0d2013-02-11 22:08:48 -080020#include "android_os_Parcel.h"
21#include "android_util_Binder.h"
John Reckf29ed282015-04-07 07:32:03 -070022#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080023#include "android/graphics/GraphicsJNI.h"
24#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080025#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040026
Tom Cherry8ed74bb2017-07-10 14:31:18 -070027#include <android-base/chrono_utils.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040028#include <JNIHelp.h>
29#include <ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080030#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080031#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080032#include <gui/Surface.h>
33#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040034#include <jni.h>
35#include <memory>
36#include <stdio.h>
Michael Wright1c9977b2016-07-12 13:30:10 -070037#include <system/graphics.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070039#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070040#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080041#include <ui/Rect.h>
42#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080043#include <utils/Log.h>
44
Mathias Agopian3866f0d2013-02-11 22:08:48 -080045// ----------------------------------------------------------------------------
46
47namespace android {
48
49static const char* const OutOfResourcesException =
50 "android/view/Surface$OutOfResourcesException";
51
52static struct {
Dan Stoza00101052014-05-02 15:23:40 -070053 jclass clazz;
54 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080055 jfieldID width;
56 jfieldID height;
57 jfieldID refreshRate;
58 jfieldID density;
59 jfieldID xDpi;
60 jfieldID yDpi;
61 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070062 jfieldID appVsyncOffsetNanos;
63 jfieldID presentationDeadlineNanos;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080064} gPhysicalDisplayInfoClassInfo;
65
Dan Stoza9890e3412014-05-22 16:12:54 -070066static struct {
67 jfieldID bottom;
68 jfieldID left;
69 jfieldID right;
70 jfieldID top;
71} gRectClassInfo;
72
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050073// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
74void DeleteScreenshot(void* addr, void* context) {
75 SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
76 delete ((ScreenshotClient*) context);
77}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080078
Svetoslav1376d602014-03-13 11:17:26 -070079static struct {
80 nsecs_t UNDEFINED_TIME_NANO;
81 jmethodID init;
82} gWindowContentFrameStatsClassInfo;
83
84static struct {
85 nsecs_t UNDEFINED_TIME_NANO;
86 jmethodID init;
87} gWindowAnimationFrameStatsClassInfo;
88
Hangyu Kuang54ac2192016-04-25 13:22:02 -070089static struct {
90 jclass clazz;
91 jmethodID ctor;
92} gHdrCapabilitiesClassInfo;
93
Robert Carr6486d312017-01-09 19:48:29 -080094static struct {
95 jclass clazz;
96 jmethodID builder;
97} gGraphicBufferClassInfo;
98
Mathias Agopian3866f0d2013-02-11 22:08:48 -080099// ----------------------------------------------------------------------------
100
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000101static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500102 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
103 jint windowType, jint ownerUid) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800104 ScopedUtfChars name(env, nameStr);
105 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700106 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800107 sp<SurfaceControl> surface = client->createSurface(
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500108 String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800109 if (surface == NULL) {
110 jniThrowException(env, OutOfResourcesException, NULL);
111 return 0;
112 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500113
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800114 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000115 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800116}
117
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000118static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800119 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800120 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800121}
122
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000123static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800124 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
125 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800126 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800127}
128
Chong Zhang47e36a32016-02-29 16:44:33 -0800129static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
130 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
131 if (ctrl != NULL) {
132 ctrl->disconnect();
133 }
134}
135
Robert Carr6486d312017-01-09 19:48:29 -0800136static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
137 int left = env->GetIntField(rectObj, gRectClassInfo.left);
138 int top = env->GetIntField(rectObj, gRectClassInfo.top);
139 int right = env->GetIntField(rectObj, gRectClassInfo.right);
140 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
141 return Rect(left, top, right, bottom);
142}
143
144static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
145 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
146 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
147 int rotation) {
148 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
149 if (displayToken == NULL) {
150 return NULL;
151 }
152 Rect sourceCrop = rectFromObj(env, sourceCropObj);
153 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800154 minLayer = INT32_MIN;
155 maxLayer = INT32_MAX;
Robert Carr6486d312017-01-09 19:48:29 -0800156 }
157 sp<GraphicBuffer> buffer;
158 status_t res = ScreenshotClient::captureToBuffer(displayToken,
159 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
160 rotation, &buffer);
161 if (res != NO_ERROR) {
162 return NULL;
163 }
164
165 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
166 gGraphicBufferClassInfo.builder,
167 buffer->getWidth(),
168 buffer->getHeight(),
169 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700170 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100171 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800172}
173
Dan Stoza9890e3412014-05-22 16:12:54 -0700174static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
175 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700176 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
177 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800178 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
179 if (displayToken == NULL) {
180 return NULL;
181 }
182
Robert Carr6486d312017-01-09 19:48:29 -0800183 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700184
Ben Wagner60126ef2015-08-07 12:13:48 -0400185 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500186 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700187 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800188 minLayer = INT32_MIN;
189 maxLayer = INT32_MAX;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500190 }
Riley Andrews1d134062014-08-21 15:47:07 -0700191
192 res = screenshot->update(displayToken, sourceCrop, width, height,
193 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500194 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800195 return NULL;
196 }
197
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400198 SkColorType colorType;
199 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500200 switch (screenshot->getFormat()) {
201 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400202 colorType = kRGBA_8888_SkColorType;
203 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500204 break;
205 }
206 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400207 colorType = kRGBA_8888_SkColorType;
208 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500209 break;
210 }
Romain Guy9505a652016-12-14 09:43:50 -0800211 case PIXEL_FORMAT_RGBA_FP16: {
212 colorType = kRGBA_F16_SkColorType;
213 alphaType = kPremul_SkAlphaType;
214 break;
215 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500216 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400217 colorType = kRGB_565_SkColorType;
218 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500219 break;
220 }
221 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500222 return NULL;
223 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800224 }
Romain Guy26a2b972017-04-17 09:39:51 -0700225
226 sk_sp<SkColorSpace> colorSpace;
227 if (screenshot->getDataSpace() == HAL_DATASPACE_DISPLAY_P3) {
228 colorSpace = SkColorSpace::MakeRGB(
229 SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
230 } else {
231 colorSpace = SkColorSpace::MakeSRGB();
232 }
233
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400234 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
235 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700236 colorType,
237 alphaType,
Romain Guy26a2b972017-04-17 09:39:51 -0700238 colorSpace);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800239
John Reckf29ed282015-04-07 07:32:03 -0700240 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500241 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
242
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400243 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700244 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800245 }
246
sergeyvc1c54062016-10-19 18:47:26 -0700247 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700248 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
249 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400250 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700251 bitmap->setImmutable();
252 return bitmap::createBitmap(env, bitmap,
253 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800254}
255
Dan Stoza9890e3412014-05-22 16:12:54 -0700256static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
257 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
258 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800259 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
260 if (displayToken != NULL) {
261 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
262 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700263 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
264 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
265 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
266 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
267 Rect sourceCrop(left, top, right, bottom);
268
Mathias Agopian0449a402013-03-01 23:01:51 -0800269 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800270 minLayer = INT32_MIN;
271 maxLayer = INT32_MAX;
Mathias Agopian0449a402013-03-01 23:01:51 -0800272 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700273 ScreenshotClient::capture(displayToken,
274 consumer->getIGraphicBufferProducer(), sourceCrop,
Robert Carr7f6e9862017-01-31 09:22:14 -0800275 width, height, minLayer, maxLayer,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800276 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800277 }
278 }
279}
280
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800281static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
282 SurfaceComposerClient::openGlobalTransaction();
283}
284
Robert Carre9953b12016-05-23 20:52:04 -0700285
286static void nativeCloseTransaction(JNIEnv* env, jclass clazz, jboolean sync) {
287 SurfaceComposerClient::closeGlobalTransaction(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800288}
289
290static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
291 SurfaceComposerClient::setAnimationTransaction();
292}
293
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000294static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800295 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
296 status_t err = ctrl->setLayer(zorder);
297 if (err < 0 && err != NO_INIT) {
298 doThrowIAE(env);
299 }
300}
301
Robert Carraf422a82017-04-10 18:34:33 -0700302static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong nativeObject,
303 jobject relativeTo, jint zorder) {
304 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
305 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
306
307 ctrl->setRelativeLayer(handle, zorder);
308}
309
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000310static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800311 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
312 status_t err = ctrl->setPosition(x, y);
313 if (err < 0 && err != NO_INIT) {
314 doThrowIAE(env);
315 }
316}
317
Robert Carr6da3cc02016-06-16 15:17:07 -0700318static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carra9408d42016-06-03 13:28:48 -0700319 jlong nativeObject) {
320 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr6da3cc02016-06-16 15:17:07 -0700321 status_t err = ctrl->setGeometryAppliesWithResize();
Robert Carra9408d42016-06-03 13:28:48 -0700322 if (err < 0 && err != NO_INIT) {
323 doThrowIAE(env);
324 }
325}
326
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000327static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800328 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
329 status_t err = ctrl->setSize(w, h);
330 if (err < 0 && err != NO_INIT) {
331 doThrowIAE(env);
332 }
333}
334
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000335static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800336 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
337 status_t err = ctrl->setFlags(flags, mask);
338 if (err < 0 && err != NO_INIT) {
339 doThrowIAE(env);
340 }
341}
342
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000343static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800344 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
345 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
346 if (!region) {
347 doThrowIAE(env);
348 return;
349 }
350
351 const SkIRect& b(region->getBounds());
352 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
353 if (region->isComplex()) {
354 SkRegion::Iterator it(*region);
355 while (!it.done()) {
356 const SkIRect& r(it.rect());
357 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
358 it.next();
359 }
360 }
361
362 status_t err = ctrl->setTransparentRegionHint(reg);
363 if (err < 0 && err != NO_INIT) {
364 doThrowIAE(env);
365 }
366}
367
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000368static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800369 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
370 status_t err = ctrl->setAlpha(alpha);
371 if (err < 0 && err != NO_INIT) {
372 doThrowIAE(env);
373 }
374}
375
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000376static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800377 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800378 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carr0edf18f2017-02-21 20:01:47 -0800379 status_t err = ctrl->setMatrix(dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800380 if (err < 0 && err != NO_INIT) {
381 doThrowIAE(env);
382 }
383}
384
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000385static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800386 jint l, jint t, jint r, jint b) {
387 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
388 Rect crop(l, t, r, b);
389 status_t err = ctrl->setCrop(crop);
390 if (err < 0 && err != NO_INIT) {
391 doThrowIAE(env);
392 }
393}
394
Pablo Ceballos27982e62016-03-09 10:50:45 -0800395static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
396 jint l, jint t, jint r, jint b) {
397 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
398 Rect crop(l, t, r, b);
399 status_t err = ctrl->setFinalCrop(crop);
400 if (err < 0 && err != NO_INIT) {
401 doThrowIAE(env);
402 }
403}
404
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000405static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800406 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
407 status_t err = ctrl->setLayerStack(layerStack);
408 if (err < 0 && err != NO_INIT) {
409 doThrowIAE(env);
410 }
411}
412
413static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
414 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
415 return javaObjectForIBinder(env, token);
416}
417
418static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
419 jboolean secure) {
420 ScopedUtfChars name(env, nameObj);
421 sp<IBinder> token(SurfaceComposerClient::createDisplay(
422 String8(name.c_str()), bool(secure)));
423 return javaObjectForIBinder(env, token);
424}
425
Jesse Hall6a6bc212013-08-08 12:15:03 -0700426static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
427 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
428 if (token == NULL) return;
429 SurfaceComposerClient::destroyDisplay(token);
430}
431
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800432static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000433 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800434 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
435 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800436 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800437 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800438 if (sur != NULL) {
439 bufferProducer = sur->getIGraphicBufferProducer();
440 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700441 status_t err = SurfaceComposerClient::setDisplaySurface(token,
442 bufferProducer);
443 if (err != NO_ERROR) {
444 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
445 " Surface created with singleBufferMode?");
446 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800447}
448
449static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
450 jobject tokenObj, jint layerStack) {
451 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
452 if (token == NULL) return;
453
454 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
455}
456
457static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
458 jobject tokenObj, jint orientation,
459 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
460 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
461 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
462 if (token == NULL) return;
463 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
464 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
465 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
466}
467
Michael Wright01e840f2014-06-26 16:03:25 -0700468static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
469 jobject tokenObj, jint width, jint height) {
470 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
471 if (token == NULL) return;
472 SurfaceComposerClient::setDisplaySize(token, width, height);
473}
474
Dan Stoza00101052014-05-02 15:23:40 -0700475static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
476 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800477 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700478 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800479
Dan Stoza00101052014-05-02 15:23:40 -0700480 Vector<DisplayInfo> configs;
481 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
482 configs.size() == 0) {
483 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800484 }
485
Dan Stoza00101052014-05-02 15:23:40 -0700486 jobjectArray configArray = env->NewObjectArray(configs.size(),
487 gPhysicalDisplayInfoClassInfo.clazz, NULL);
488
489 for (size_t c = 0; c < configs.size(); ++c) {
490 const DisplayInfo& info = configs[c];
491 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
492 gPhysicalDisplayInfoClassInfo.ctor);
493 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
494 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
495 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
496 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
497 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
498 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
499 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700500 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
501 info.appVsyncOffset);
502 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
503 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700504 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
505 env->DeleteLocalRef(infoObj);
506 }
507
508 return configArray;
509}
510
511static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
512 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
513 if (token == NULL) return -1;
514 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
515}
516
517static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
518 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
519 if (token == NULL) return JNI_FALSE;
520 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
521 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800522}
523
Michael Wright1c9977b2016-07-12 13:30:10 -0700524static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
525 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
526 if (token == NULL) return NULL;
527 Vector<android_color_mode_t> colorModes;
528 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
529 colorModes.isEmpty()) {
530 return NULL;
531 }
532
533 jintArray colorModesArray = env->NewIntArray(colorModes.size());
534 if (colorModesArray == NULL) {
535 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
536 return NULL;
537 }
538 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
539 for (size_t i = 0; i < colorModes.size(); i++) {
540 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
541 }
542 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
543 return colorModesArray;
544}
545
546static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
547 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
548 if (token == NULL) return -1;
549 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
550}
551
552static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
553 jobject tokenObj, jint colorMode) {
554 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
555 if (token == NULL) return JNI_FALSE;
556 status_t err = SurfaceComposerClient::setActiveColorMode(token,
557 static_cast<android_color_mode_t>(colorMode));
558 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
559}
560
Prashant Malanic55929a2014-05-25 01:59:21 -0700561static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800562 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
563 if (token == NULL) return;
564
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700565 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700566 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700567 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800568}
569
Svetoslav1376d602014-03-13 11:17:26 -0700570static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
571 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
572 status_t err = ctrl->clearLayerFrameStats();
573
574 if (err < 0 && err != NO_INIT) {
575 doThrowIAE(env);
576 }
577
578 // The other end is not ready, just report we failed.
579 if (err == NO_INIT) {
580 return JNI_FALSE;
581 }
582
583 return JNI_TRUE;
584}
585
586static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
587 jobject outStats) {
588 FrameStats stats;
589
590 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
591 status_t err = ctrl->getLayerFrameStats(&stats);
592 if (err < 0 && err != NO_INIT) {
593 doThrowIAE(env);
594 }
595
596 // The other end is not ready, fine just return empty stats.
597 if (err == NO_INIT) {
598 return JNI_FALSE;
599 }
600
601 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
602 size_t frameCount = stats.desiredPresentTimesNano.size();
603
604 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
605 if (postedTimesNanoDst == NULL) {
606 return JNI_FALSE;
607 }
608
609 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
610 if (presentedTimesNanoDst == NULL) {
611 return JNI_FALSE;
612 }
613
614 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
615 if (readyTimesNanoDst == NULL) {
616 return JNI_FALSE;
617 }
618
619 nsecs_t postedTimesNanoSrc[frameCount];
620 nsecs_t presentedTimesNanoSrc[frameCount];
621 nsecs_t readyTimesNanoSrc[frameCount];
622
623 for (size_t i = 0; i < frameCount; i++) {
624 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
625 if (postedTimeNano == INT64_MAX) {
626 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
627 }
628 postedTimesNanoSrc[i] = postedTimeNano;
629
630 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
631 if (presentedTimeNano == INT64_MAX) {
632 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
633 }
634 presentedTimesNanoSrc[i] = presentedTimeNano;
635
636 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
637 if (readyTimeNano == INT64_MAX) {
638 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
639 }
640 readyTimesNanoSrc[i] = readyTimeNano;
641 }
642
643 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
644 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
645 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
646
647 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
648 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
649
650 if (env->ExceptionCheck()) {
651 return JNI_FALSE;
652 }
653
654 return JNI_TRUE;
655}
656
657static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
658 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
659
660 if (err < 0 && err != NO_INIT) {
661 doThrowIAE(env);
662 }
663
664 // The other end is not ready, just report we failed.
665 if (err == NO_INIT) {
666 return JNI_FALSE;
667 }
668
669 return JNI_TRUE;
670}
671
672static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
673 FrameStats stats;
674
675 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
676 if (err < 0 && err != NO_INIT) {
677 doThrowIAE(env);
678 }
679
680 // The other end is not ready, fine just return empty stats.
681 if (err == NO_INIT) {
682 return JNI_FALSE;
683 }
684
685 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
686 size_t frameCount = stats.desiredPresentTimesNano.size();
687
688 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
689 if (presentedTimesNanoDst == NULL) {
690 return JNI_FALSE;
691 }
692
693 nsecs_t presentedTimesNanoSrc[frameCount];
694
695 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700696 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700697 if (presentedTimeNano == INT64_MAX) {
698 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
699 }
700 presentedTimesNanoSrc[i] = presentedTimeNano;
701 }
702
703 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
704
705 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
706 presentedTimesNanoDst);
707
708 if (env->ExceptionCheck()) {
709 return JNI_FALSE;
710 }
711
712 return JNI_TRUE;
713}
714
Rob Carr64e516f2015-10-29 00:20:45 +0000715static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
716 jobject handleObject, jlong frameNumber) {
717 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
718 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
719
720 ctrl->deferTransactionUntil(handle, frameNumber);
721}
722
Robert Carrd5c7dd62017-03-08 10:39:30 -0800723static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong nativeObject,
724 jlong surfaceObject, jlong frameNumber) {
725 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
726 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
727
728 ctrl->deferTransactionUntil(barrier, frameNumber);
729}
730
731static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong nativeObject,
732 jobject newParentObject) {
733 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
734 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
735
736 ctrl->reparentChildren(handle);
737}
738
739static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong nativeObject) {
740 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
741 ctrl->detachChildren();
742}
743
Robert Carr1ca6a332016-04-11 18:00:43 -0700744static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
745 jint scalingMode) {
746 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
747
748 ctrl->setOverrideScalingMode(scalingMode);
749}
750
Rob Carr64e516f2015-10-29 00:20:45 +0000751static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
752 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
753
754 return javaObjectForIBinder(env, ctrl->getHandle());
755}
756
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700757static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
758 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
759 if (token == NULL) return NULL;
760
761 HdrCapabilities capabilities;
762 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
763
764 const auto& types = capabilities.getSupportedHdrTypes();
765 auto typesArray = env->NewIntArray(types.size());
766 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
767
Michael Wright9ff94c02016-03-30 18:05:40 -0700768 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700769 typesArray, capabilities.getDesiredMaxLuminance(),
770 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
771}
772
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800773// ----------------------------------------------------------------------------
774
Daniel Micay76f6a862015-09-19 17:31:01 -0400775static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500776 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800777 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000778 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800779 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000780 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800781 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800782 {"nativeDisconnect", "(J)V",
783 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700784 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800785 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700786 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800787 (void*)nativeScreenshot },
788 {"nativeOpenTransaction", "()V",
789 (void*)nativeOpenTransaction },
Robert Carre9953b12016-05-23 20:52:04 -0700790 {"nativeCloseTransaction", "(Z)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800791 (void*)nativeCloseTransaction },
792 {"nativeSetAnimationTransaction", "()V",
793 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000794 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800795 (void*)nativeSetLayer },
Robert Carraf422a82017-04-10 18:34:33 -0700796 {"nativeSetRelativeLayer", "(JLandroid/os/IBinder;I)V",
797 (void*)nativeSetRelativeLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000798 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800799 (void*)nativeSetPosition },
Robert Carr6da3cc02016-06-16 15:17:07 -0700800 {"nativeSetGeometryAppliesWithResize", "(J)V",
801 (void*)nativeSetGeometryAppliesWithResize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000802 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800803 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000804 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800805 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000806 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800807 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000808 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800809 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000810 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800811 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000812 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800813 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800814 {"nativeSetFinalCrop", "(JIIII)V",
815 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000816 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800817 (void*)nativeSetLayerStack },
818 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
819 (void*)nativeGetBuiltInDisplay },
820 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
821 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700822 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
823 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000824 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800825 (void*)nativeSetDisplaySurface },
826 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
827 (void*)nativeSetDisplayLayerStack },
828 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
829 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700830 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
831 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700832 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
833 (void*)nativeGetDisplayConfigs },
834 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
835 (void*)nativeGetActiveConfig },
836 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
837 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700838 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
839 (void*)nativeGetDisplayColorModes},
840 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
841 (void*)nativeGetActiveColorMode},
842 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
843 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700844 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
845 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700846 {"nativeClearContentFrameStats", "(J)Z",
847 (void*)nativeClearContentFrameStats },
848 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
849 (void*)nativeGetContentFrameStats },
850 {"nativeClearAnimationFrameStats", "()Z",
851 (void*)nativeClearAnimationFrameStats },
852 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
853 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700854 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
855 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000856 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
857 (void*)nativeDeferTransactionUntil },
Robert Carrd5c7dd62017-03-08 10:39:30 -0800858 {"nativeDeferTransactionUntilSurface", "(JJJ)V",
859 (void*)nativeDeferTransactionUntilSurface },
860 {"nativeReparentChildren", "(JLandroid/os/IBinder;)V",
861 (void*)nativeReparentChildren } ,
862 {"nativeSeverChildren", "(J)V",
863 (void*)nativeSeverChildren } ,
Robert Carr1ca6a332016-04-11 18:00:43 -0700864 {"nativeSetOverrideScalingMode", "(JI)V",
865 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000866 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -0700867 (void*)nativeGetHandle },
Robert Carr6486d312017-01-09 19:48:29 -0800868 {"nativeScreenshotToBuffer",
869 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
870 (void*)nativeScreenshotToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800871};
872
873int register_android_view_SurfaceControl(JNIEnv* env)
874{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800875 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800876 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
877
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800878 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
879 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
880 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
881 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
882 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
883 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
884 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
885 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
886 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
887 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
888 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
889 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
890 clazz, "appVsyncOffsetNanos", "J");
891 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
892 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700893
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800894 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
895 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
896 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
897 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
898 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700899
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800900 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
901 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
902 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700903 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
904
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800905 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
906 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
907 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700908 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
909
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800910 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
911 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
912 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700913 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
914
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700915 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
916 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
917 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
918 "([IFFF)V");
919
Robert Carr6486d312017-01-09 19:48:29 -0800920 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
921 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
922 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
923 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
924
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800925 return err;
926}
927
928};