blob: f77e6c4fa7b81b53f119ba3856d01c9fffdfe9f4 [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>
Steven Moreland2279b252017-07-19 09:50:45 -070028#include <nativehelper/JNIHelp.h>
29#include <nativehelper/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
Robert Carre13b58e2017-08-31 14:50:44 -0700101static jlong nativeCreateTransaction(JNIEnv* env, jclass clazz) {
102 return reinterpret_cast<jlong>(new SurfaceComposerClient::Transaction);
103}
104
105static void releaseTransaction(SurfaceComposerClient::Transaction* t) {
106 delete t;
107}
108
109static jlong nativeGetNativeTransactionFinalizer(JNIEnv* env, jclass clazz) {
110 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&releaseTransaction));
111}
112
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000113static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500114 jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
115 jint windowType, jint ownerUid) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800116 ScopedUtfChars name(env, nameStr);
117 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
Robert Carr838120c2016-11-01 18:31:12 -0700118 SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800119 sp<SurfaceControl> surface = client->createSurface(
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500120 String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800121 if (surface == NULL) {
122 jniThrowException(env, OutOfResourcesException, NULL);
123 return 0;
124 }
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500125
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800126 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000127 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800128}
129
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000130static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800131 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800132 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800133}
134
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000135static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800136 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
137 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800138 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800139}
140
Chong Zhang47e36a32016-02-29 16:44:33 -0800141static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
142 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
143 if (ctrl != NULL) {
144 ctrl->disconnect();
145 }
146}
147
Robert Carr6486d312017-01-09 19:48:29 -0800148static Rect rectFromObj(JNIEnv* env, jobject rectObj) {
149 int left = env->GetIntField(rectObj, gRectClassInfo.left);
150 int top = env->GetIntField(rectObj, gRectClassInfo.top);
151 int right = env->GetIntField(rectObj, gRectClassInfo.right);
152 int bottom = env->GetIntField(rectObj, gRectClassInfo.bottom);
153 return Rect(left, top, right, bottom);
154}
155
156static jobject nativeScreenshotToBuffer(JNIEnv* env, jclass clazz,
157 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
158 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
159 int rotation) {
160 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
161 if (displayToken == NULL) {
162 return NULL;
163 }
164 Rect sourceCrop = rectFromObj(env, sourceCropObj);
165 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800166 minLayer = INT32_MIN;
167 maxLayer = INT32_MAX;
Robert Carr6486d312017-01-09 19:48:29 -0800168 }
169 sp<GraphicBuffer> buffer;
170 status_t res = ScreenshotClient::captureToBuffer(displayToken,
171 sourceCrop, width, height, minLayer, maxLayer, useIdentityTransform,
172 rotation, &buffer);
173 if (res != NO_ERROR) {
174 return NULL;
175 }
176
177 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
178 gGraphicBufferClassInfo.builder,
179 buffer->getWidth(),
180 buffer->getHeight(),
181 buffer->getPixelFormat(),
Mathias Agopian113fd302017-05-25 18:31:04 -0700182 (jint)buffer->getUsage(),
Patrik Torstensson511a8082017-03-27 15:04:11 +0100183 (jlong)buffer.get());
Robert Carr6486d312017-01-09 19:48:29 -0800184}
185
Dan Stoza9890e3412014-05-22 16:12:54 -0700186static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
187 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700188 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
189 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800190 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
191 if (displayToken == NULL) {
192 return NULL;
193 }
194
Robert Carr6486d312017-01-09 19:48:29 -0800195 Rect sourceCrop = rectFromObj(env, sourceCropObj);
Dan Stoza9890e3412014-05-22 16:12:54 -0700196
Ben Wagner60126ef2015-08-07 12:13:48 -0400197 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500198 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700199 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800200 minLayer = INT32_MIN;
201 maxLayer = INT32_MAX;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500202 }
Riley Andrews1d134062014-08-21 15:47:07 -0700203
204 res = screenshot->update(displayToken, sourceCrop, width, height,
205 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500206 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800207 return NULL;
208 }
209
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400210 SkColorType colorType;
211 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500212 switch (screenshot->getFormat()) {
213 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400214 colorType = kRGBA_8888_SkColorType;
215 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500216 break;
217 }
218 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400219 colorType = kRGBA_8888_SkColorType;
220 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500221 break;
222 }
Romain Guy9505a652016-12-14 09:43:50 -0800223 case PIXEL_FORMAT_RGBA_FP16: {
224 colorType = kRGBA_F16_SkColorType;
225 alphaType = kPremul_SkAlphaType;
226 break;
227 }
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500228 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400229 colorType = kRGB_565_SkColorType;
230 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500231 break;
232 }
233 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500234 return NULL;
235 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800236 }
Romain Guy26a2b972017-04-17 09:39:51 -0700237
238 sk_sp<SkColorSpace> colorSpace;
239 if (screenshot->getDataSpace() == HAL_DATASPACE_DISPLAY_P3) {
240 colorSpace = SkColorSpace::MakeRGB(
241 SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
242 } else {
243 colorSpace = SkColorSpace::MakeSRGB();
244 }
245
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400246 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
247 screenshot->getHeight(),
Romain Guy253f2c22016-09-28 17:34:42 -0700248 colorType,
249 alphaType,
Romain Guy26a2b972017-04-17 09:39:51 -0700250 colorSpace);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800251
John Reckf29ed282015-04-07 07:32:03 -0700252 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500253 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
254
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400255 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700256 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800257 }
258
sergeyvc1c54062016-10-19 18:47:26 -0700259 auto bitmap = new Bitmap(
John Reckf29ed282015-04-07 07:32:03 -0700260 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
Leon Scroggins IIIf51a80d2017-07-12 10:46:35 -0400261 screenshotInfo, rowBytes);
Ben Wagner60126ef2015-08-07 12:13:48 -0400262 screenshot.release();
sergeyvc1c54062016-10-19 18:47:26 -0700263 bitmap->setImmutable();
264 return bitmap::createBitmap(env, bitmap,
265 android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800266}
267
Dan Stoza9890e3412014-05-22 16:12:54 -0700268static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
269 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
270 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800271 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
272 if (displayToken != NULL) {
273 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
274 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700275 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
276 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
277 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
278 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
279 Rect sourceCrop(left, top, right, bottom);
280
Mathias Agopian0449a402013-03-01 23:01:51 -0800281 if (allLayers) {
Robert Carrfb09bcf2017-01-26 11:52:35 -0800282 minLayer = INT32_MIN;
283 maxLayer = INT32_MAX;
Mathias Agopian0449a402013-03-01 23:01:51 -0800284 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700285 ScreenshotClient::capture(displayToken,
286 consumer->getIGraphicBufferProducer(), sourceCrop,
Robert Carr7f6e9862017-01-31 09:22:14 -0800287 width, height, minLayer, maxLayer,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800288 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800289 }
290 }
291}
292
chaviw1cda84c2017-10-23 16:47:10 -0700293static void nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken,
chaviwfbe47df2017-11-10 16:14:49 -0800294 jobject surfaceObj, jobject sourceCropObj, jfloat frameScale) {
chaviw1cda84c2017-10-23 16:47:10 -0700295
296 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
297 if (layerHandle == NULL) {
298 return;
299 }
300
301 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
302 if (consumer == NULL) {
303 return;
304 }
305
chaviwfbe47df2017-11-10 16:14:49 -0800306 Rect sourceCrop;
307 if (sourceCropObj != NULL) {
308 sourceCrop = rectFromObj(env, sourceCropObj);
309 }
310
311 ScreenshotClient::captureLayers(layerHandle, consumer->getIGraphicBufferProducer(), sourceCrop,
312 frameScale);
313}
314
315static jobject nativeCaptureLayersToBuffer(JNIEnv* env, jclass clazz, jobject layerHandleToken,
316 jobject sourceCropObj, jfloat frameScale) {
317
318 sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
319 if (layerHandle == NULL) {
320 return NULL;
321 }
322
323 Rect sourceCrop;
324 if (sourceCropObj != NULL) {
325 sourceCrop = rectFromObj(env, sourceCropObj);
326 }
327
328 sp<GraphicBuffer> buffer;
329 status_t res = ScreenshotClient::captureLayersToBuffer(layerHandle, sourceCrop, frameScale,
330 &buffer);
331 if (res != NO_ERROR) {
332 return NULL;
333 }
334
335 return env->CallStaticObjectMethod(gGraphicBufferClassInfo.clazz,
336 gGraphicBufferClassInfo.builder,
337 buffer->getWidth(),
338 buffer->getHeight(),
339 buffer->getPixelFormat(),
340 (jint)buffer->getUsage(),
341 (jlong)buffer.get());
chaviw1cda84c2017-10-23 16:47:10 -0700342}
343
Robert Carre13b58e2017-08-31 14:50:44 -0700344static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) {
345 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
346 transaction->apply(sync);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800347}
348
Robert Carrb1579c82017-09-05 14:54:47 -0700349static void nativeMergeTransaction(JNIEnv* env, jclass clazz,
350 jlong transactionObj, jlong otherTransactionObj) {
351 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
352 auto otherTransaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(
353 otherTransactionObj);
354 transaction->merge(std::move(*otherTransaction));
355}
356
Robert Carre13b58e2017-08-31 14:50:44 -0700357static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz, jlong transactionObj) {
358 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
359 transaction->setAnimationTransaction();
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800360}
361
Robert Carre13b58e2017-08-31 14:50:44 -0700362static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
363 jlong nativeObject, jint zorder) {
364 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800365
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800366 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700367 transaction->setLayer(ctrl, zorder);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800368}
369
Robert Carre13b58e2017-08-31 14:50:44 -0700370static void nativeSetRelativeLayer(JNIEnv* env, jclass clazz, jlong transactionObj,
371 jlong nativeObject,
Robert Carraf422a82017-04-10 18:34:33 -0700372 jobject relativeTo, jint zorder) {
Robert Carre13b58e2017-08-31 14:50:44 -0700373
Robert Carraf422a82017-04-10 18:34:33 -0700374 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
375 sp<IBinder> handle = ibinderForJavaObject(env, relativeTo);
376
Robert Carre13b58e2017-08-31 14:50:44 -0700377 {
378 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
379 transaction->setRelativeLayer(ctrl, handle, zorder);
380 }
Robert Carraf422a82017-04-10 18:34:33 -0700381}
382
Robert Carre13b58e2017-08-31 14:50:44 -0700383static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong transactionObj,
384 jlong nativeObject, jfloat x, jfloat y) {
385 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
386
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800387 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700388 transaction->setPosition(ctrl, x, y);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800389}
390
Robert Carr6da3cc02016-06-16 15:17:07 -0700391static void nativeSetGeometryAppliesWithResize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700392jlong transactionObj,
Robert Carra9408d42016-06-03 13:28:48 -0700393 jlong nativeObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700394 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
395
Robert Carra9408d42016-06-03 13:28:48 -0700396 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700397 transaction->setGeometryAppliesWithResize(ctrl);
Robert Carra9408d42016-06-03 13:28:48 -0700398}
399
Robert Carre13b58e2017-08-31 14:50:44 -0700400static void nativeSetSize(JNIEnv* env, jclass clazz, jlong transactionObj,
401 jlong nativeObject, jint w, jint h) {
402 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
403
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800404 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700405 transaction->setSize(ctrl, w, h);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800406}
407
Robert Carre13b58e2017-08-31 14:50:44 -0700408static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong transactionObj,
409 jlong nativeObject, jint flags, jint mask) {
410 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
411
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800412 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700413 transaction->setFlags(ctrl, flags, mask);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800414}
415
Robert Carre13b58e2017-08-31 14:50:44 -0700416static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong transactionObj,
417 jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800418 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
419 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
420 if (!region) {
421 doThrowIAE(env);
422 return;
423 }
424
425 const SkIRect& b(region->getBounds());
426 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
427 if (region->isComplex()) {
428 SkRegion::Iterator it(*region);
429 while (!it.done()) {
430 const SkIRect& r(it.rect());
431 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
432 it.next();
433 }
434 }
435
Robert Carre13b58e2017-08-31 14:50:44 -0700436 {
437 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
438 transaction->setTransparentRegionHint(ctrl, reg);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800439 }
440}
441
Robert Carre13b58e2017-08-31 14:50:44 -0700442static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
443 jlong nativeObject, jfloat alpha) {
444 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
445
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800446 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700447 transaction->setAlpha(ctrl, alpha);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800448}
449
Robert Carre13b58e2017-08-31 14:50:44 -0700450static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
451 jlong nativeObject, jfloatArray fColor) {
452 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
chaviw0dd03f52017-08-25 12:15:26 -0700453 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700454
chaviw0dd03f52017-08-25 12:15:26 -0700455 float* floatColors = env->GetFloatArrayElements(fColor, 0);
456 half3 color(floatColors[0], floatColors[1], floatColors[2]);
Robert Carre13b58e2017-08-31 14:50:44 -0700457 transaction->setColor(ctrl, color);
chaviw0dd03f52017-08-25 12:15:26 -0700458}
459
Robert Carre13b58e2017-08-31 14:50:44 -0700460static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong transactionObj,
461 jlong nativeObject,
Robert Carr0edf18f2017-02-21 20:01:47 -0800462 jfloat dsdx, jfloat dtdx, jfloat dtdy, jfloat dsdy) {
Robert Carre13b58e2017-08-31 14:50:44 -0700463 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
464
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800465 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700466 transaction->setMatrix(ctrl, dsdx, dtdx, dtdy, dsdy);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800467}
468
Robert Carre13b58e2017-08-31 14:50:44 -0700469static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
470 jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800471 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700472 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
473
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800474 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
475 Rect crop(l, t, r, b);
Robert Carre13b58e2017-08-31 14:50:44 -0700476 transaction->setCrop(ctrl, crop);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800477}
478
Robert Carre13b58e2017-08-31 14:50:44 -0700479static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong transactionObj,
480 jlong nativeObject,
Pablo Ceballos27982e62016-03-09 10:50:45 -0800481 jint l, jint t, jint r, jint b) {
Robert Carre13b58e2017-08-31 14:50:44 -0700482 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
483
Pablo Ceballos27982e62016-03-09 10:50:45 -0800484 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
485 Rect crop(l, t, r, b);
Robert Carre13b58e2017-08-31 14:50:44 -0700486 transaction->setFinalCrop(ctrl, crop);
Pablo Ceballos27982e62016-03-09 10:50:45 -0800487}
488
Robert Carre13b58e2017-08-31 14:50:44 -0700489static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong transactionObj,
490 jlong nativeObject, jint layerStack) {
491 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
492
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800493 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700494 transaction->setLayerStack(ctrl, layerStack);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800495}
496
497static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
498 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
499 return javaObjectForIBinder(env, token);
500}
501
502static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
503 jboolean secure) {
504 ScopedUtfChars name(env, nameObj);
505 sp<IBinder> token(SurfaceComposerClient::createDisplay(
506 String8(name.c_str()), bool(secure)));
507 return javaObjectForIBinder(env, token);
508}
509
Jesse Hall6a6bc212013-08-08 12:15:03 -0700510static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
511 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
512 if (token == NULL) return;
513 SurfaceComposerClient::destroyDisplay(token);
514}
515
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800516static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700517 jlong transactionObj,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000518 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800519 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
520 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800521 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800522 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800523 if (sur != NULL) {
524 bufferProducer = sur->getIGraphicBufferProducer();
525 }
Robert Carre13b58e2017-08-31 14:50:44 -0700526
527
528 status_t err = NO_ERROR;
529 {
530 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
531 err = transaction->setDisplaySurface(token,
532 bufferProducer);
533 }
Pablo Ceballosaff2f942016-07-29 14:49:55 -0700534 if (err != NO_ERROR) {
535 doThrowIAE(env, "Illegal Surface, could not enable async mode. Was this"
536 " Surface created with singleBufferMode?");
537 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800538}
539
540static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700541 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800542 jobject tokenObj, jint layerStack) {
Robert Carre13b58e2017-08-31 14:50:44 -0700543
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800544 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
545 if (token == NULL) return;
546
Robert Carre13b58e2017-08-31 14:50:44 -0700547 {
548 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
549 transaction->setDisplayLayerStack(token, layerStack);
550 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800551}
552
553static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700554 jlong transactionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800555 jobject tokenObj, jint orientation,
556 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
557 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
558 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
559 if (token == NULL) return;
560 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
561 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
Robert Carre13b58e2017-08-31 14:50:44 -0700562
563 {
564 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
565 transaction->setDisplayProjection(token, orientation, layerStackRect, displayRect);
566 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800567}
568
Michael Wright01e840f2014-06-26 16:03:25 -0700569static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
Robert Carre13b58e2017-08-31 14:50:44 -0700570 jlong transactionObj,
Michael Wright01e840f2014-06-26 16:03:25 -0700571 jobject tokenObj, jint width, jint height) {
572 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
573 if (token == NULL) return;
Robert Carre13b58e2017-08-31 14:50:44 -0700574
575 {
576 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
577 transaction->setDisplaySize(token, width, height);
578 }
Michael Wright01e840f2014-06-26 16:03:25 -0700579}
580
Dan Stoza00101052014-05-02 15:23:40 -0700581static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
582 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800583 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700584 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800585
Dan Stoza00101052014-05-02 15:23:40 -0700586 Vector<DisplayInfo> configs;
587 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
588 configs.size() == 0) {
589 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800590 }
591
Dan Stoza00101052014-05-02 15:23:40 -0700592 jobjectArray configArray = env->NewObjectArray(configs.size(),
593 gPhysicalDisplayInfoClassInfo.clazz, NULL);
594
595 for (size_t c = 0; c < configs.size(); ++c) {
596 const DisplayInfo& info = configs[c];
597 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
598 gPhysicalDisplayInfoClassInfo.ctor);
599 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
600 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
601 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
602 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
603 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
604 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
605 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700606 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
607 info.appVsyncOffset);
608 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
609 info.presentationDeadline);
Dan Stoza00101052014-05-02 15:23:40 -0700610 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
611 env->DeleteLocalRef(infoObj);
612 }
613
614 return configArray;
615}
616
617static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
618 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
619 if (token == NULL) return -1;
620 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
621}
622
623static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
624 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
625 if (token == NULL) return JNI_FALSE;
626 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
627 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800628}
629
Michael Wright1c9977b2016-07-12 13:30:10 -0700630static jintArray nativeGetDisplayColorModes(JNIEnv* env, jclass, jobject tokenObj) {
631 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
632 if (token == NULL) return NULL;
633 Vector<android_color_mode_t> colorModes;
634 if (SurfaceComposerClient::getDisplayColorModes(token, &colorModes) != NO_ERROR ||
635 colorModes.isEmpty()) {
636 return NULL;
637 }
638
639 jintArray colorModesArray = env->NewIntArray(colorModes.size());
640 if (colorModesArray == NULL) {
641 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
642 return NULL;
643 }
644 jint* colorModesArrayValues = env->GetIntArrayElements(colorModesArray, 0);
645 for (size_t i = 0; i < colorModes.size(); i++) {
646 colorModesArrayValues[i] = static_cast<jint>(colorModes[i]);
647 }
648 env->ReleaseIntArrayElements(colorModesArray, colorModesArrayValues, 0);
649 return colorModesArray;
650}
651
652static jint nativeGetActiveColorMode(JNIEnv* env, jclass, jobject tokenObj) {
653 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
654 if (token == NULL) return -1;
655 return static_cast<jint>(SurfaceComposerClient::getActiveColorMode(token));
656}
657
658static jboolean nativeSetActiveColorMode(JNIEnv* env, jclass,
659 jobject tokenObj, jint colorMode) {
660 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
661 if (token == NULL) return JNI_FALSE;
662 status_t err = SurfaceComposerClient::setActiveColorMode(token,
663 static_cast<android_color_mode_t>(colorMode));
664 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
665}
666
Prashant Malanic55929a2014-05-25 01:59:21 -0700667static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800668 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
669 if (token == NULL) return;
670
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700671 android::base::Timer t;
Prashant Malanic55929a2014-05-25 01:59:21 -0700672 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Tom Cherry8ed74bb2017-07-10 14:31:18 -0700673 if (t.duration() > 100ms) ALOGD("Excessive delay in setPowerMode()");
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800674}
675
Svetoslav1376d602014-03-13 11:17:26 -0700676static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
677 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
678 status_t err = ctrl->clearLayerFrameStats();
679
680 if (err < 0 && err != NO_INIT) {
681 doThrowIAE(env);
682 }
683
684 // The other end is not ready, just report we failed.
685 if (err == NO_INIT) {
686 return JNI_FALSE;
687 }
688
689 return JNI_TRUE;
690}
691
692static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
693 jobject outStats) {
694 FrameStats stats;
695
696 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
697 status_t err = ctrl->getLayerFrameStats(&stats);
698 if (err < 0 && err != NO_INIT) {
699 doThrowIAE(env);
700 }
701
702 // The other end is not ready, fine just return empty stats.
703 if (err == NO_INIT) {
704 return JNI_FALSE;
705 }
706
707 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
708 size_t frameCount = stats.desiredPresentTimesNano.size();
709
710 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
711 if (postedTimesNanoDst == NULL) {
712 return JNI_FALSE;
713 }
714
715 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
716 if (presentedTimesNanoDst == NULL) {
717 return JNI_FALSE;
718 }
719
720 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
721 if (readyTimesNanoDst == NULL) {
722 return JNI_FALSE;
723 }
724
725 nsecs_t postedTimesNanoSrc[frameCount];
726 nsecs_t presentedTimesNanoSrc[frameCount];
727 nsecs_t readyTimesNanoSrc[frameCount];
728
729 for (size_t i = 0; i < frameCount; i++) {
730 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
731 if (postedTimeNano == INT64_MAX) {
732 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
733 }
734 postedTimesNanoSrc[i] = postedTimeNano;
735
736 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
737 if (presentedTimeNano == INT64_MAX) {
738 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
739 }
740 presentedTimesNanoSrc[i] = presentedTimeNano;
741
742 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
743 if (readyTimeNano == INT64_MAX) {
744 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
745 }
746 readyTimesNanoSrc[i] = readyTimeNano;
747 }
748
749 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
750 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
751 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
752
753 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
754 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
755
756 if (env->ExceptionCheck()) {
757 return JNI_FALSE;
758 }
759
760 return JNI_TRUE;
761}
762
763static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
764 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
765
766 if (err < 0 && err != NO_INIT) {
767 doThrowIAE(env);
768 }
769
770 // The other end is not ready, just report we failed.
771 if (err == NO_INIT) {
772 return JNI_FALSE;
773 }
774
775 return JNI_TRUE;
776}
777
778static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
779 FrameStats stats;
780
781 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
782 if (err < 0 && err != NO_INIT) {
783 doThrowIAE(env);
784 }
785
786 // The other end is not ready, fine just return empty stats.
787 if (err == NO_INIT) {
788 return JNI_FALSE;
789 }
790
791 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
792 size_t frameCount = stats.desiredPresentTimesNano.size();
793
794 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
795 if (presentedTimesNanoDst == NULL) {
796 return JNI_FALSE;
797 }
798
799 nsecs_t presentedTimesNanoSrc[frameCount];
800
801 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700802 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700803 if (presentedTimeNano == INT64_MAX) {
804 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
805 }
806 presentedTimesNanoSrc[i] = presentedTimeNano;
807 }
808
809 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
810
811 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
812 presentedTimesNanoDst);
813
814 if (env->ExceptionCheck()) {
815 return JNI_FALSE;
816 }
817
818 return JNI_TRUE;
819}
820
Robert Carre13b58e2017-08-31 14:50:44 -0700821static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong transactionObj,
822 jlong nativeObject,
Rob Carr64e516f2015-10-29 00:20:45 +0000823 jobject handleObject, jlong frameNumber) {
824 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
825 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
826
Robert Carre13b58e2017-08-31 14:50:44 -0700827 {
828 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
829 transaction->deferTransactionUntil(ctrl, handle, frameNumber);
830 }
Rob Carr64e516f2015-10-29 00:20:45 +0000831}
832
Robert Carre13b58e2017-08-31 14:50:44 -0700833static void nativeDeferTransactionUntilSurface(JNIEnv* env, jclass clazz, jlong transactionObj,
834 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800835 jlong surfaceObject, jlong frameNumber) {
Robert Carre13b58e2017-08-31 14:50:44 -0700836 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
837
Robert Carrd5c7dd62017-03-08 10:39:30 -0800838 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
839 sp<Surface> barrier = reinterpret_cast<Surface *>(surfaceObject);
840
Robert Carre13b58e2017-08-31 14:50:44 -0700841 transaction->deferTransactionUntil(ctrl, barrier, frameNumber);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800842}
843
Robert Carre13b58e2017-08-31 14:50:44 -0700844static void nativeReparentChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
845 jlong nativeObject,
Robert Carrd5c7dd62017-03-08 10:39:30 -0800846 jobject newParentObject) {
Robert Carre13b58e2017-08-31 14:50:44 -0700847
Robert Carrd5c7dd62017-03-08 10:39:30 -0800848 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
849 sp<IBinder> handle = ibinderForJavaObject(env, newParentObject);
850
Robert Carre13b58e2017-08-31 14:50:44 -0700851 {
852 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
853 transaction->reparentChildren(ctrl, handle);
854 }
Robert Carrd5c7dd62017-03-08 10:39:30 -0800855}
856
Robert Carre13b58e2017-08-31 14:50:44 -0700857static void nativeReparent(JNIEnv* env, jclass clazz, jlong transactionObj,
858 jlong nativeObject,
chaviw76431402017-09-18 16:50:05 -0700859 jobject newParentObject) {
chaviw63542382017-08-17 17:39:29 -0700860 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
861 sp<IBinder> parentHandle = ibinderForJavaObject(env, newParentObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700862
863 {
864 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
865 transaction->reparent(ctrl, parentHandle);
866 }
chaviw63542382017-08-17 17:39:29 -0700867}
868
Robert Carre13b58e2017-08-31 14:50:44 -0700869static void nativeSeverChildren(JNIEnv* env, jclass clazz, jlong transactionObj,
870 jlong nativeObject) {
871 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
872
Robert Carrd5c7dd62017-03-08 10:39:30 -0800873 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Robert Carre13b58e2017-08-31 14:50:44 -0700874 transaction->detachChildren(ctrl);
Robert Carrd5c7dd62017-03-08 10:39:30 -0800875}
876
Robert Carre13b58e2017-08-31 14:50:44 -0700877static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong transactionObj,
878 jlong nativeObject,
Robert Carr1ca6a332016-04-11 18:00:43 -0700879 jint scalingMode) {
Robert Carre13b58e2017-08-31 14:50:44 -0700880 auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
Robert Carr1ca6a332016-04-11 18:00:43 -0700881
Robert Carre13b58e2017-08-31 14:50:44 -0700882 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
883 transaction->setOverrideScalingMode(ctrl, scalingMode);
Robert Carr1ca6a332016-04-11 18:00:43 -0700884}
885
Rob Carr64e516f2015-10-29 00:20:45 +0000886static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
887 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
Rob Carr64e516f2015-10-29 00:20:45 +0000888 return javaObjectForIBinder(env, ctrl->getHandle());
889}
890
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700891static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
892 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
893 if (token == NULL) return NULL;
894
895 HdrCapabilities capabilities;
896 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
897
898 const auto& types = capabilities.getSupportedHdrTypes();
899 auto typesArray = env->NewIntArray(types.size());
900 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
901
Michael Wright9ff94c02016-03-30 18:05:40 -0700902 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gHdrCapabilitiesClassInfo.ctor,
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700903 typesArray, capabilities.getDesiredMaxLuminance(),
904 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
905}
906
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800907// ----------------------------------------------------------------------------
908
Daniel Micay76f6a862015-09-19 17:31:01 -0400909static const JNINativeMethod sSurfaceControlMethods[] = {
Albert Chaulk3bf2e572016-11-22 13:59:19 -0500910 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800911 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000912 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800913 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000914 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800915 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800916 {"nativeDisconnect", "(J)V",
917 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700918 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800919 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700920 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800921 (void*)nativeScreenshot },
Robert Carre13b58e2017-08-31 14:50:44 -0700922 {"nativeCreateTransaction", "()J",
923 (void*)nativeCreateTransaction },
924 {"nativeApplyTransaction", "(JZ)V",
925 (void*)nativeApplyTransaction },
926 {"nativeGetNativeTransactionFinalizer", "()J",
927 (void*)nativeGetNativeTransactionFinalizer },
Robert Carrb1579c82017-09-05 14:54:47 -0700928 {"nativeMergeTransaction", "(JJ)V",
929 (void*)nativeMergeTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -0700930 {"nativeSetAnimationTransaction", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800931 (void*)nativeSetAnimationTransaction },
Robert Carre13b58e2017-08-31 14:50:44 -0700932 {"nativeSetLayer", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800933 (void*)nativeSetLayer },
Robert Carre13b58e2017-08-31 14:50:44 -0700934 {"nativeSetRelativeLayer", "(JJLandroid/os/IBinder;I)V",
Robert Carraf422a82017-04-10 18:34:33 -0700935 (void*)nativeSetRelativeLayer },
Robert Carre13b58e2017-08-31 14:50:44 -0700936 {"nativeSetPosition", "(JJFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800937 (void*)nativeSetPosition },
Robert Carre13b58e2017-08-31 14:50:44 -0700938 {"nativeSetGeometryAppliesWithResize", "(JJ)V",
Robert Carr6da3cc02016-06-16 15:17:07 -0700939 (void*)nativeSetGeometryAppliesWithResize },
Robert Carre13b58e2017-08-31 14:50:44 -0700940 {"nativeSetSize", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800941 (void*)nativeSetSize },
Robert Carre13b58e2017-08-31 14:50:44 -0700942 {"nativeSetTransparentRegionHint", "(JJLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800943 (void*)nativeSetTransparentRegionHint },
Robert Carre13b58e2017-08-31 14:50:44 -0700944 {"nativeSetAlpha", "(JJF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800945 (void*)nativeSetAlpha },
Robert Carre13b58e2017-08-31 14:50:44 -0700946 {"nativeSetColor", "(JJ[F)V",
chaviw0dd03f52017-08-25 12:15:26 -0700947 (void*)nativeSetColor },
Robert Carre13b58e2017-08-31 14:50:44 -0700948 {"nativeSetMatrix", "(JJFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800949 (void*)nativeSetMatrix },
Robert Carre13b58e2017-08-31 14:50:44 -0700950 {"nativeSetFlags", "(JJII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800951 (void*)nativeSetFlags },
Robert Carre13b58e2017-08-31 14:50:44 -0700952 {"nativeSetWindowCrop", "(JJIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800953 (void*)nativeSetWindowCrop },
Robert Carre13b58e2017-08-31 14:50:44 -0700954 {"nativeSetFinalCrop", "(JJIIII)V",
Pablo Ceballos27982e62016-03-09 10:50:45 -0800955 (void*)nativeSetFinalCrop },
Robert Carre13b58e2017-08-31 14:50:44 -0700956 {"nativeSetLayerStack", "(JJI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800957 (void*)nativeSetLayerStack },
958 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
959 (void*)nativeGetBuiltInDisplay },
960 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
961 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700962 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
963 (void*)nativeDestroyDisplay },
Robert Carre13b58e2017-08-31 14:50:44 -0700964 {"nativeSetDisplaySurface", "(JLandroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800965 (void*)nativeSetDisplaySurface },
Robert Carre13b58e2017-08-31 14:50:44 -0700966 {"nativeSetDisplayLayerStack", "(JLandroid/os/IBinder;I)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800967 (void*)nativeSetDisplayLayerStack },
Robert Carre13b58e2017-08-31 14:50:44 -0700968 {"nativeSetDisplayProjection", "(JLandroid/os/IBinder;IIIIIIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800969 (void*)nativeSetDisplayProjection },
Robert Carre13b58e2017-08-31 14:50:44 -0700970 {"nativeSetDisplaySize", "(JLandroid/os/IBinder;II)V",
Michael Wright01e840f2014-06-26 16:03:25 -0700971 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700972 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
973 (void*)nativeGetDisplayConfigs },
974 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
975 (void*)nativeGetActiveConfig },
976 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
977 (void*)nativeSetActiveConfig },
Michael Wright1c9977b2016-07-12 13:30:10 -0700978 {"nativeGetDisplayColorModes", "(Landroid/os/IBinder;)[I",
979 (void*)nativeGetDisplayColorModes},
980 {"nativeGetActiveColorMode", "(Landroid/os/IBinder;)I",
981 (void*)nativeGetActiveColorMode},
982 {"nativeSetActiveColorMode", "(Landroid/os/IBinder;I)Z",
983 (void*)nativeSetActiveColorMode},
Michael Wright9ff94c02016-03-30 18:05:40 -0700984 {"nativeGetHdrCapabilities", "(Landroid/os/IBinder;)Landroid/view/Display$HdrCapabilities;",
985 (void*)nativeGetHdrCapabilities },
Svetoslav1376d602014-03-13 11:17:26 -0700986 {"nativeClearContentFrameStats", "(J)Z",
987 (void*)nativeClearContentFrameStats },
988 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
989 (void*)nativeGetContentFrameStats },
990 {"nativeClearAnimationFrameStats", "()Z",
991 (void*)nativeClearAnimationFrameStats },
992 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
993 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700994 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
995 (void*)nativeSetDisplayPowerMode },
Robert Carre13b58e2017-08-31 14:50:44 -0700996 {"nativeDeferTransactionUntil", "(JJLandroid/os/IBinder;J)V",
Rob Carr64e516f2015-10-29 00:20:45 +0000997 (void*)nativeDeferTransactionUntil },
Robert Carre13b58e2017-08-31 14:50:44 -0700998 {"nativeDeferTransactionUntilSurface", "(JJJJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -0800999 (void*)nativeDeferTransactionUntilSurface },
Robert Carre13b58e2017-08-31 14:50:44 -07001000 {"nativeReparentChildren", "(JJLandroid/os/IBinder;)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001001 (void*)nativeReparentChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001002 {"nativeReparent", "(JJLandroid/os/IBinder;)V",
chaviw76431402017-09-18 16:50:05 -07001003 (void*)nativeReparent },
Robert Carre13b58e2017-08-31 14:50:44 -07001004 {"nativeSeverChildren", "(JJ)V",
Robert Carrd5c7dd62017-03-08 10:39:30 -08001005 (void*)nativeSeverChildren } ,
Robert Carre13b58e2017-08-31 14:50:44 -07001006 {"nativeSetOverrideScalingMode", "(JJI)V",
Robert Carr1ca6a332016-04-11 18:00:43 -07001007 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +00001008 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
Robert Carr6da3cc02016-06-16 15:17:07 -07001009 (void*)nativeGetHandle },
Robert Carr6486d312017-01-09 19:48:29 -08001010 {"nativeScreenshotToBuffer",
1011 "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;",
1012 (void*)nativeScreenshotToBuffer },
chaviwfbe47df2017-11-10 16:14:49 -08001013 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;F)V",
chaviw1cda84c2017-10-23 16:47:10 -07001014 (void*)nativeCaptureLayers },
chaviwfbe47df2017-11-10 16:14:49 -08001015 {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
1016 (void*)nativeCaptureLayersToBuffer },
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001017};
1018
1019int register_android_view_SurfaceControl(JNIEnv* env)
1020{
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001021 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001022 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
1023
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001024 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
1025 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
1026 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
1027 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
1028 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
1029 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
1030 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
1031 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
1032 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
1033 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
1034 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
1035 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
1036 clazz, "appVsyncOffsetNanos", "J");
1037 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
1038 clazz, "presentationDeadlineNanos", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001039
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001040 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
1041 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
1042 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
1043 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
1044 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -07001045
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001046 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
1047 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
1048 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -07001049 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
1050
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001051 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
1052 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1053 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001054 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1055
Andreas Gampeed6b9df2014-11-20 22:02:20 -08001056 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
1057 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
1058 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -07001059 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
1060
Hangyu Kuang54ac2192016-04-25 13:22:02 -07001061 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
1062 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
1063 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
1064 "([IFFF)V");
1065
Robert Carr6486d312017-01-09 19:48:29 -08001066 jclass graphicsBufferClazz = FindClassOrDie(env, "android/graphics/GraphicBuffer");
1067 gGraphicBufferClassInfo.clazz = MakeGlobalRefOrDie(env, graphicsBufferClazz);
1068 gGraphicBufferClassInfo.builder = GetStaticMethodIDOrDie(env, graphicsBufferClazz,
1069 "createFromExisting", "(IIIIJ)Landroid/graphics/GraphicBuffer;");
1070
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001071 return err;
1072}
1073
1074};