blob: 5d5f85634a0261576475822e8ee2b3603c7e8aa2 [file] [log] [blame]
Mathias Agopian3866f0d2013-02-11 22:08:48 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "SurfaceControl"
18
Mathias Agopian3866f0d2013-02-11 22:08:48 -080019#include "android_os_Parcel.h"
20#include "android_util_Binder.h"
John Reckf29ed282015-04-07 07:32:03 -070021#include "android/graphics/Bitmap.h"
Mathias Agopian3866f0d2013-02-11 22:08:48 -080022#include "android/graphics/GraphicsJNI.h"
23#include "android/graphics/Region.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080024#include "core_jni_helpers.h"
Ben Wagner60126ef2015-08-07 12:13:48 -040025
26#include <JNIHelp.h>
27#include <ScopedUtfChars.h>
Mathias Agopian0449a402013-03-01 23:01:51 -080028#include <android_runtime/android_view_Surface.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080029#include <android_runtime/android_view_SurfaceSession.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080030#include <gui/Surface.h>
31#include <gui/SurfaceComposerClient.h>
Ben Wagner60126ef2015-08-07 12:13:48 -040032#include <jni.h>
33#include <memory>
34#include <stdio.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080035#include <ui/DisplayInfo.h>
Hangyu Kuang54ac2192016-04-25 13:22:02 -070036#include <ui/HdrCapabilities.h>
Svetoslav1376d602014-03-13 11:17:26 -070037#include <ui/FrameStats.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080038#include <ui/Rect.h>
39#include <ui/Region.h>
Mathias Agopian3866f0d2013-02-11 22:08:48 -080040#include <utils/Log.h>
41
Mathias Agopian3866f0d2013-02-11 22:08:48 -080042// ----------------------------------------------------------------------------
43
44namespace android {
45
46static const char* const OutOfResourcesException =
47 "android/view/Surface$OutOfResourcesException";
48
49static struct {
Dan Stoza00101052014-05-02 15:23:40 -070050 jclass clazz;
51 jmethodID ctor;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080052 jfieldID width;
53 jfieldID height;
54 jfieldID refreshRate;
55 jfieldID density;
56 jfieldID xDpi;
57 jfieldID yDpi;
58 jfieldID secure;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -070059 jfieldID appVsyncOffsetNanos;
60 jfieldID presentationDeadlineNanos;
Dan Stoza904f4852015-08-31 12:01:48 -070061 jfieldID colorTransform;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080062} gPhysicalDisplayInfoClassInfo;
63
Dan Stoza9890e3412014-05-22 16:12:54 -070064static struct {
65 jfieldID bottom;
66 jfieldID left;
67 jfieldID right;
68 jfieldID top;
69} gRectClassInfo;
70
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050071// Implements SkMallocPixelRef::ReleaseProc, to delete the screenshot on unref.
72void DeleteScreenshot(void* addr, void* context) {
73 SkASSERT(addr == ((ScreenshotClient*) context)->getPixels());
74 delete ((ScreenshotClient*) context);
75}
Mathias Agopian3866f0d2013-02-11 22:08:48 -080076
Svetoslav1376d602014-03-13 11:17:26 -070077static struct {
78 nsecs_t UNDEFINED_TIME_NANO;
79 jmethodID init;
80} gWindowContentFrameStatsClassInfo;
81
82static struct {
83 nsecs_t UNDEFINED_TIME_NANO;
84 jmethodID init;
85} gWindowAnimationFrameStatsClassInfo;
86
Hangyu Kuang54ac2192016-04-25 13:22:02 -070087static struct {
88 jclass clazz;
89 jmethodID ctor;
90} gHdrCapabilitiesClassInfo;
91
Mathias Agopian3866f0d2013-02-11 22:08:48 -080092// ----------------------------------------------------------------------------
93
Ashok Bhat36bef0b2014-01-20 20:08:01 +000094static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
Mathias Agopian3866f0d2013-02-11 22:08:48 -080095 jstring nameStr, jint w, jint h, jint format, jint flags) {
96 ScopedUtfChars name(env, nameStr);
97 sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
98 sp<SurfaceControl> surface = client->createSurface(
99 String8(name.c_str()), w, h, format, flags);
100 if (surface == NULL) {
101 jniThrowException(env, OutOfResourcesException, NULL);
102 return 0;
103 }
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800104 surface->incStrong((void *)nativeCreate);
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000105 return reinterpret_cast<jlong>(surface.get());
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800106}
107
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000108static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800109 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800110 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800111}
112
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000113static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800114 sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
115 ctrl->clear();
Mathias Agopianb1d90c82013-03-06 17:45:42 -0800116 ctrl->decStrong((void *)nativeCreate);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800117}
118
Chong Zhang47e36a32016-02-29 16:44:33 -0800119static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
120 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
121 if (ctrl != NULL) {
122 ctrl->disconnect();
123 }
124}
125
Dan Stoza9890e3412014-05-22 16:12:54 -0700126static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
127 jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
Riley Andrews1d134062014-08-21 15:47:07 -0700128 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
129 int rotation) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800130 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
131 if (displayToken == NULL) {
132 return NULL;
133 }
134
Dan Stoza9890e3412014-05-22 16:12:54 -0700135 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
136 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
137 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
138 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
139 Rect sourceCrop(left, top, right, bottom);
140
Ben Wagner60126ef2015-08-07 12:13:48 -0400141 std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500142 status_t res;
Riley Andrews1d134062014-08-21 15:47:07 -0700143 if (allLayers) {
144 minLayer = 0;
Andreas Gampe0f0b4912014-11-12 08:03:48 -0800145 maxLayer = -1;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500146 }
Riley Andrews1d134062014-08-21 15:47:07 -0700147
148 res = screenshot->update(displayToken, sourceCrop, width, height,
149 minLayer, maxLayer, useIdentityTransform, static_cast<uint32_t>(rotation));
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500150 if (res != NO_ERROR) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800151 return NULL;
152 }
153
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400154 SkColorType colorType;
155 SkAlphaType alphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500156 switch (screenshot->getFormat()) {
157 case PIXEL_FORMAT_RGBX_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400158 colorType = kRGBA_8888_SkColorType;
159 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500160 break;
161 }
162 case PIXEL_FORMAT_RGBA_8888: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400163 colorType = kRGBA_8888_SkColorType;
164 alphaType = kPremul_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500165 break;
166 }
167 case PIXEL_FORMAT_RGB_565: {
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400168 colorType = kRGB_565_SkColorType;
169 alphaType = kOpaque_SkAlphaType;
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500170 break;
171 }
172 default: {
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500173 return NULL;
174 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800175 }
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400176 SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
177 screenshot->getHeight(),
178 colorType, alphaType);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800179
John Reckf29ed282015-04-07 07:32:03 -0700180 const size_t rowBytes =
Derek Sollenbergerb644a3b2014-01-17 15:45:10 -0500181 screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
182
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400183 if (!screenshotInfo.width() || !screenshotInfo.height()) {
John Reckf29ed282015-04-07 07:32:03 -0700184 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800185 }
186
John Reckf29ed282015-04-07 07:32:03 -0700187 Bitmap* bitmap = new Bitmap(
188 (void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
189 screenshotInfo, rowBytes, nullptr);
Ben Wagner60126ef2015-08-07 12:13:48 -0400190 screenshot.release();
John Reckae2e8b42015-05-06 14:55:05 -0700191 bitmap->peekAtPixelRef()->setImmutable();
John Reckf29ed282015-04-07 07:32:03 -0700192
Chris Craik1abf5d62013-08-16 12:47:03 -0700193 return GraphicsJNI::createBitmap(env, bitmap,
194 GraphicsJNI::kBitmapCreateFlag_Premultiplied, NULL);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800195}
196
Dan Stoza9890e3412014-05-22 16:12:54 -0700197static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,
198 jobject surfaceObj, jobject sourceCropObj, jint width, jint height,
199 jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform) {
Mathias Agopian0449a402013-03-01 23:01:51 -0800200 sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
201 if (displayToken != NULL) {
202 sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj);
203 if (consumer != NULL) {
Dan Stoza9890e3412014-05-22 16:12:54 -0700204 int left = env->GetIntField(sourceCropObj, gRectClassInfo.left);
205 int top = env->GetIntField(sourceCropObj, gRectClassInfo.top);
206 int right = env->GetIntField(sourceCropObj, gRectClassInfo.right);
207 int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
208 Rect sourceCrop(left, top, right, bottom);
209
Mathias Agopian0449a402013-03-01 23:01:51 -0800210 if (allLayers) {
211 minLayer = 0;
212 maxLayer = -1;
213 }
Dan Stoza9890e3412014-05-22 16:12:54 -0700214 ScreenshotClient::capture(displayToken,
215 consumer->getIGraphicBufferProducer(), sourceCrop,
Dan Stoza16ec12a2014-02-14 15:06:55 -0800216 width, height, uint32_t(minLayer), uint32_t(maxLayer),
217 useIdentityTransform);
Mathias Agopian0449a402013-03-01 23:01:51 -0800218 }
219 }
220}
221
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800222static void nativeOpenTransaction(JNIEnv* env, jclass clazz) {
223 SurfaceComposerClient::openGlobalTransaction();
224}
225
226static void nativeCloseTransaction(JNIEnv* env, jclass clazz) {
227 SurfaceComposerClient::closeGlobalTransaction();
228}
229
230static void nativeSetAnimationTransaction(JNIEnv* env, jclass clazz) {
231 SurfaceComposerClient::setAnimationTransaction();
232}
233
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000234static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800235 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
236 status_t err = ctrl->setLayer(zorder);
237 if (err < 0 && err != NO_INIT) {
238 doThrowIAE(env);
239 }
240}
241
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000242static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800243 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
244 status_t err = ctrl->setPosition(x, y);
245 if (err < 0 && err != NO_INIT) {
246 doThrowIAE(env);
247 }
248}
249
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000250static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800251 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
252 status_t err = ctrl->setSize(w, h);
253 if (err < 0 && err != NO_INIT) {
254 doThrowIAE(env);
255 }
256}
257
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000258static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800259 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
260 status_t err = ctrl->setFlags(flags, mask);
261 if (err < 0 && err != NO_INIT) {
262 doThrowIAE(env);
263 }
264}
265
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000266static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800267 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
268 SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
269 if (!region) {
270 doThrowIAE(env);
271 return;
272 }
273
274 const SkIRect& b(region->getBounds());
275 Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
276 if (region->isComplex()) {
277 SkRegion::Iterator it(*region);
278 while (!it.done()) {
279 const SkIRect& r(it.rect());
280 reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
281 it.next();
282 }
283 }
284
285 status_t err = ctrl->setTransparentRegionHint(reg);
286 if (err < 0 && err != NO_INIT) {
287 doThrowIAE(env);
288 }
289}
290
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000291static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800292 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
293 status_t err = ctrl->setAlpha(alpha);
294 if (err < 0 && err != NO_INIT) {
295 doThrowIAE(env);
296 }
297}
298
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000299static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800300 jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
301 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
302 status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
303 if (err < 0 && err != NO_INIT) {
304 doThrowIAE(env);
305 }
306}
307
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000308static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800309 jint l, jint t, jint r, jint b) {
310 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
311 Rect crop(l, t, r, b);
312 status_t err = ctrl->setCrop(crop);
313 if (err < 0 && err != NO_INIT) {
314 doThrowIAE(env);
315 }
316}
317
Pablo Ceballos27982e62016-03-09 10:50:45 -0800318static void nativeSetFinalCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
319 jint l, jint t, jint r, jint b) {
320 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
321 Rect crop(l, t, r, b);
322 status_t err = ctrl->setFinalCrop(crop);
323 if (err < 0 && err != NO_INIT) {
324 doThrowIAE(env);
325 }
326}
327
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000328static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800329 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
330 status_t err = ctrl->setLayerStack(layerStack);
331 if (err < 0 && err != NO_INIT) {
332 doThrowIAE(env);
333 }
334}
335
336static jobject nativeGetBuiltInDisplay(JNIEnv* env, jclass clazz, jint id) {
337 sp<IBinder> token(SurfaceComposerClient::getBuiltInDisplay(id));
338 return javaObjectForIBinder(env, token);
339}
340
341static jobject nativeCreateDisplay(JNIEnv* env, jclass clazz, jstring nameObj,
342 jboolean secure) {
343 ScopedUtfChars name(env, nameObj);
344 sp<IBinder> token(SurfaceComposerClient::createDisplay(
345 String8(name.c_str()), bool(secure)));
346 return javaObjectForIBinder(env, token);
347}
348
Jesse Hall6a6bc212013-08-08 12:15:03 -0700349static void nativeDestroyDisplay(JNIEnv* env, jclass clazz, jobject tokenObj) {
350 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
351 if (token == NULL) return;
352 SurfaceComposerClient::destroyDisplay(token);
353}
354
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800355static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000356 jobject tokenObj, jlong nativeSurfaceObject) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800357 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
358 if (token == NULL) return;
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800359 sp<IGraphicBufferProducer> bufferProducer;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800360 sp<Surface> sur(reinterpret_cast<Surface *>(nativeSurfaceObject));
Mathias Agopianffddc9b2013-02-25 15:56:31 -0800361 if (sur != NULL) {
362 bufferProducer = sur->getIGraphicBufferProducer();
363 }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800364 SurfaceComposerClient::setDisplaySurface(token, bufferProducer);
365}
366
367static void nativeSetDisplayLayerStack(JNIEnv* env, jclass clazz,
368 jobject tokenObj, jint layerStack) {
369 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
370 if (token == NULL) return;
371
372 SurfaceComposerClient::setDisplayLayerStack(token, layerStack);
373}
374
375static void nativeSetDisplayProjection(JNIEnv* env, jclass clazz,
376 jobject tokenObj, jint orientation,
377 jint layerStackRect_left, jint layerStackRect_top, jint layerStackRect_right, jint layerStackRect_bottom,
378 jint displayRect_left, jint displayRect_top, jint displayRect_right, jint displayRect_bottom) {
379 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
380 if (token == NULL) return;
381 Rect layerStackRect(layerStackRect_left, layerStackRect_top, layerStackRect_right, layerStackRect_bottom);
382 Rect displayRect(displayRect_left, displayRect_top, displayRect_right, displayRect_bottom);
383 SurfaceComposerClient::setDisplayProjection(token, orientation, layerStackRect, displayRect);
384}
385
Michael Wright01e840f2014-06-26 16:03:25 -0700386static void nativeSetDisplaySize(JNIEnv* env, jclass clazz,
387 jobject tokenObj, jint width, jint height) {
388 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
389 if (token == NULL) return;
390 SurfaceComposerClient::setDisplaySize(token, width, height);
391}
392
Dan Stoza00101052014-05-02 15:23:40 -0700393static jobjectArray nativeGetDisplayConfigs(JNIEnv* env, jclass clazz,
394 jobject tokenObj) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800395 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
Dan Stoza00101052014-05-02 15:23:40 -0700396 if (token == NULL) return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800397
Dan Stoza00101052014-05-02 15:23:40 -0700398 Vector<DisplayInfo> configs;
399 if (SurfaceComposerClient::getDisplayConfigs(token, &configs) != NO_ERROR ||
400 configs.size() == 0) {
401 return NULL;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800402 }
403
Dan Stoza00101052014-05-02 15:23:40 -0700404 jobjectArray configArray = env->NewObjectArray(configs.size(),
405 gPhysicalDisplayInfoClassInfo.clazz, NULL);
406
407 for (size_t c = 0; c < configs.size(); ++c) {
408 const DisplayInfo& info = configs[c];
409 jobject infoObj = env->NewObject(gPhysicalDisplayInfoClassInfo.clazz,
410 gPhysicalDisplayInfoClassInfo.ctor);
411 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.width, info.w);
412 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.height, info.h);
413 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.refreshRate, info.fps);
414 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.density, info.density);
415 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.xDpi, info.xdpi);
416 env->SetFloatField(infoObj, gPhysicalDisplayInfoClassInfo.yDpi, info.ydpi);
417 env->SetBooleanField(infoObj, gPhysicalDisplayInfoClassInfo.secure, info.secure);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700418 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos,
419 info.appVsyncOffset);
420 env->SetLongField(infoObj, gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos,
421 info.presentationDeadline);
Dan Stoza904f4852015-08-31 12:01:48 -0700422 env->SetIntField(infoObj, gPhysicalDisplayInfoClassInfo.colorTransform,
423 info.colorTransform);
Dan Stoza00101052014-05-02 15:23:40 -0700424 env->SetObjectArrayElement(configArray, static_cast<jsize>(c), infoObj);
425 env->DeleteLocalRef(infoObj);
426 }
427
428 return configArray;
429}
430
431static jint nativeGetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj) {
432 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
433 if (token == NULL) return -1;
434 return static_cast<jint>(SurfaceComposerClient::getActiveConfig(token));
435}
436
437static jboolean nativeSetActiveConfig(JNIEnv* env, jclass clazz, jobject tokenObj, jint id) {
438 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
439 if (token == NULL) return JNI_FALSE;
440 status_t err = SurfaceComposerClient::setActiveConfig(token, static_cast<int>(id));
441 return err == NO_ERROR ? JNI_TRUE : JNI_FALSE;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800442}
443
Prashant Malanic55929a2014-05-25 01:59:21 -0700444static void nativeSetDisplayPowerMode(JNIEnv* env, jclass clazz, jobject tokenObj, jint mode) {
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800445 sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
446 if (token == NULL) return;
447
Prashant Malanic55929a2014-05-25 01:59:21 -0700448 ALOGD_IF_SLOW(100, "Excessive delay in setPowerMode()");
449 SurfaceComposerClient::setDisplayPowerMode(token, mode);
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800450}
451
Svetoslav1376d602014-03-13 11:17:26 -0700452static jboolean nativeClearContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject) {
453 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
454 status_t err = ctrl->clearLayerFrameStats();
455
456 if (err < 0 && err != NO_INIT) {
457 doThrowIAE(env);
458 }
459
460 // The other end is not ready, just report we failed.
461 if (err == NO_INIT) {
462 return JNI_FALSE;
463 }
464
465 return JNI_TRUE;
466}
467
468static jboolean nativeGetContentFrameStats(JNIEnv* env, jclass clazz, jlong nativeObject,
469 jobject outStats) {
470 FrameStats stats;
471
472 SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
473 status_t err = ctrl->getLayerFrameStats(&stats);
474 if (err < 0 && err != NO_INIT) {
475 doThrowIAE(env);
476 }
477
478 // The other end is not ready, fine just return empty stats.
479 if (err == NO_INIT) {
480 return JNI_FALSE;
481 }
482
483 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
484 size_t frameCount = stats.desiredPresentTimesNano.size();
485
486 jlongArray postedTimesNanoDst = env->NewLongArray(frameCount);
487 if (postedTimesNanoDst == NULL) {
488 return JNI_FALSE;
489 }
490
491 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
492 if (presentedTimesNanoDst == NULL) {
493 return JNI_FALSE;
494 }
495
496 jlongArray readyTimesNanoDst = env->NewLongArray(frameCount);
497 if (readyTimesNanoDst == NULL) {
498 return JNI_FALSE;
499 }
500
501 nsecs_t postedTimesNanoSrc[frameCount];
502 nsecs_t presentedTimesNanoSrc[frameCount];
503 nsecs_t readyTimesNanoSrc[frameCount];
504
505 for (size_t i = 0; i < frameCount; i++) {
506 nsecs_t postedTimeNano = stats.desiredPresentTimesNano[i];
507 if (postedTimeNano == INT64_MAX) {
508 postedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
509 }
510 postedTimesNanoSrc[i] = postedTimeNano;
511
512 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
513 if (presentedTimeNano == INT64_MAX) {
514 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
515 }
516 presentedTimesNanoSrc[i] = presentedTimeNano;
517
518 nsecs_t readyTimeNano = stats.frameReadyTimesNano[i];
519 if (readyTimeNano == INT64_MAX) {
520 readyTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
521 }
522 readyTimesNanoSrc[i] = readyTimeNano;
523 }
524
525 env->SetLongArrayRegion(postedTimesNanoDst, 0, frameCount, postedTimesNanoSrc);
526 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
527 env->SetLongArrayRegion(readyTimesNanoDst, 0, frameCount, readyTimesNanoSrc);
528
529 env->CallVoidMethod(outStats, gWindowContentFrameStatsClassInfo.init, refreshPeriodNano,
530 postedTimesNanoDst, presentedTimesNanoDst, readyTimesNanoDst);
531
532 if (env->ExceptionCheck()) {
533 return JNI_FALSE;
534 }
535
536 return JNI_TRUE;
537}
538
539static jboolean nativeClearAnimationFrameStats(JNIEnv* env, jclass clazz) {
540 status_t err = SurfaceComposerClient::clearAnimationFrameStats();
541
542 if (err < 0 && err != NO_INIT) {
543 doThrowIAE(env);
544 }
545
546 // The other end is not ready, just report we failed.
547 if (err == NO_INIT) {
548 return JNI_FALSE;
549 }
550
551 return JNI_TRUE;
552}
553
554static jboolean nativeGetAnimationFrameStats(JNIEnv* env, jclass clazz, jobject outStats) {
555 FrameStats stats;
556
557 status_t err = SurfaceComposerClient::getAnimationFrameStats(&stats);
558 if (err < 0 && err != NO_INIT) {
559 doThrowIAE(env);
560 }
561
562 // The other end is not ready, fine just return empty stats.
563 if (err == NO_INIT) {
564 return JNI_FALSE;
565 }
566
567 jlong refreshPeriodNano = static_cast<jlong>(stats.refreshPeriodNano);
568 size_t frameCount = stats.desiredPresentTimesNano.size();
569
570 jlongArray presentedTimesNanoDst = env->NewLongArray(frameCount);
571 if (presentedTimesNanoDst == NULL) {
572 return JNI_FALSE;
573 }
574
575 nsecs_t presentedTimesNanoSrc[frameCount];
576
577 for (size_t i = 0; i < frameCount; i++) {
Allen Hairac5eda32014-04-24 11:50:37 -0700578 nsecs_t presentedTimeNano = stats.actualPresentTimesNano[i];
Svetoslav1376d602014-03-13 11:17:26 -0700579 if (presentedTimeNano == INT64_MAX) {
580 presentedTimeNano = gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO;
581 }
582 presentedTimesNanoSrc[i] = presentedTimeNano;
583 }
584
585 env->SetLongArrayRegion(presentedTimesNanoDst, 0, frameCount, presentedTimesNanoSrc);
586
587 env->CallVoidMethod(outStats, gWindowAnimationFrameStatsClassInfo.init, refreshPeriodNano,
588 presentedTimesNanoDst);
589
590 if (env->ExceptionCheck()) {
591 return JNI_FALSE;
592 }
593
594 return JNI_TRUE;
595}
596
Rob Carr64e516f2015-10-29 00:20:45 +0000597
598static void nativeDeferTransactionUntil(JNIEnv* env, jclass clazz, jlong nativeObject,
599 jobject handleObject, jlong frameNumber) {
600 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
601 sp<IBinder> handle = ibinderForJavaObject(env, handleObject);
602
603 ctrl->deferTransactionUntil(handle, frameNumber);
604}
605
Robert Carr1ca6a332016-04-11 18:00:43 -0700606static void nativeSetOverrideScalingMode(JNIEnv* env, jclass clazz, jlong nativeObject,
607 jint scalingMode) {
608 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
609
610 ctrl->setOverrideScalingMode(scalingMode);
611}
612
Rob Carr64e516f2015-10-29 00:20:45 +0000613static jobject nativeGetHandle(JNIEnv* env, jclass clazz, jlong nativeObject) {
614 auto ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
615
616 return javaObjectForIBinder(env, ctrl->getHandle());
617}
618
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700619static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject tokenObject) {
620 sp<IBinder> token(ibinderForJavaObject(env, tokenObject));
621 if (token == NULL) return NULL;
622
623 HdrCapabilities capabilities;
624 SurfaceComposerClient::getHdrCapabilities(token, &capabilities);
625
626 const auto& types = capabilities.getSupportedHdrTypes();
627 auto typesArray = env->NewIntArray(types.size());
628 env->SetIntArrayRegion(typesArray, 0, types.size(), types.data());
629
630 return env->NewObject(gHdrCapabilitiesClassInfo.clazz, gPhysicalDisplayInfoClassInfo.ctor,
631 typesArray, capabilities.getDesiredMaxLuminance(),
632 capabilities.getDesiredMaxAverageLuminance(), capabilities.getDesiredMinLuminance());
633}
634
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800635// ----------------------------------------------------------------------------
636
Daniel Micay76f6a862015-09-19 17:31:01 -0400637static const JNINativeMethod sSurfaceControlMethods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000638 {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800639 (void*)nativeCreate },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000640 {"nativeRelease", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800641 (void*)nativeRelease },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000642 {"nativeDestroy", "(J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800643 (void*)nativeDestroy },
Chong Zhang47e36a32016-02-29 16:44:33 -0800644 {"nativeDisconnect", "(J)V",
645 (void*)nativeDisconnect },
Riley Andrews1d134062014-08-21 15:47:07 -0700646 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
Mathias Agopian0449a402013-03-01 23:01:51 -0800647 (void*)nativeScreenshotBitmap },
Dan Stoza9890e3412014-05-22 16:12:54 -0700648 {"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800649 (void*)nativeScreenshot },
650 {"nativeOpenTransaction", "()V",
651 (void*)nativeOpenTransaction },
652 {"nativeCloseTransaction", "()V",
653 (void*)nativeCloseTransaction },
654 {"nativeSetAnimationTransaction", "()V",
655 (void*)nativeSetAnimationTransaction },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000656 {"nativeSetLayer", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800657 (void*)nativeSetLayer },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000658 {"nativeSetPosition", "(JFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800659 (void*)nativeSetPosition },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000660 {"nativeSetSize", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800661 (void*)nativeSetSize },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000662 {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800663 (void*)nativeSetTransparentRegionHint },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000664 {"nativeSetAlpha", "(JF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800665 (void*)nativeSetAlpha },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000666 {"nativeSetMatrix", "(JFFFF)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800667 (void*)nativeSetMatrix },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000668 {"nativeSetFlags", "(JII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800669 (void*)nativeSetFlags },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000670 {"nativeSetWindowCrop", "(JIIII)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800671 (void*)nativeSetWindowCrop },
Pablo Ceballos27982e62016-03-09 10:50:45 -0800672 {"nativeSetFinalCrop", "(JIIII)V",
673 (void*)nativeSetFinalCrop },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000674 {"nativeSetLayerStack", "(JI)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800675 (void*)nativeSetLayerStack },
676 {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
677 (void*)nativeGetBuiltInDisplay },
678 {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
679 (void*)nativeCreateDisplay },
Jesse Hall6a6bc212013-08-08 12:15:03 -0700680 {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
681 (void*)nativeDestroyDisplay },
Ashok Bhat36bef0b2014-01-20 20:08:01 +0000682 {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800683 (void*)nativeSetDisplaySurface },
684 {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
685 (void*)nativeSetDisplayLayerStack },
686 {"nativeSetDisplayProjection", "(Landroid/os/IBinder;IIIIIIIII)V",
687 (void*)nativeSetDisplayProjection },
Michael Wright01e840f2014-06-26 16:03:25 -0700688 {"nativeSetDisplaySize", "(Landroid/os/IBinder;II)V",
689 (void*)nativeSetDisplaySize },
Dan Stoza00101052014-05-02 15:23:40 -0700690 {"nativeGetDisplayConfigs", "(Landroid/os/IBinder;)[Landroid/view/SurfaceControl$PhysicalDisplayInfo;",
691 (void*)nativeGetDisplayConfigs },
692 {"nativeGetActiveConfig", "(Landroid/os/IBinder;)I",
693 (void*)nativeGetActiveConfig },
694 {"nativeSetActiveConfig", "(Landroid/os/IBinder;I)Z",
695 (void*)nativeSetActiveConfig },
Svetoslav1376d602014-03-13 11:17:26 -0700696 {"nativeClearContentFrameStats", "(J)Z",
697 (void*)nativeClearContentFrameStats },
698 {"nativeGetContentFrameStats", "(JLandroid/view/WindowContentFrameStats;)Z",
699 (void*)nativeGetContentFrameStats },
700 {"nativeClearAnimationFrameStats", "()Z",
701 (void*)nativeClearAnimationFrameStats },
702 {"nativeGetAnimationFrameStats", "(Landroid/view/WindowAnimationFrameStats;)Z",
703 (void*)nativeGetAnimationFrameStats },
Prashant Malanic55929a2014-05-25 01:59:21 -0700704 {"nativeSetDisplayPowerMode", "(Landroid/os/IBinder;I)V",
705 (void*)nativeSetDisplayPowerMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000706 {"nativeDeferTransactionUntil", "(JLandroid/os/IBinder;J)V",
707 (void*)nativeDeferTransactionUntil },
Robert Carr1ca6a332016-04-11 18:00:43 -0700708 {"nativeSetOverrideScalingMode", "(JI)V",
709 (void*)nativeSetOverrideScalingMode },
Rob Carr64e516f2015-10-29 00:20:45 +0000710 {"nativeGetHandle", "(J)Landroid/os/IBinder;",
711 (void*)nativeGetHandle }
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800712};
713
714int register_android_view_SurfaceControl(JNIEnv* env)
715{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800716 int err = RegisterMethodsOrDie(env, "android/view/SurfaceControl",
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800717 sSurfaceControlMethods, NELEM(sSurfaceControlMethods));
718
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800719 jclass clazz = FindClassOrDie(env, "android/view/SurfaceControl$PhysicalDisplayInfo");
720 gPhysicalDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
721 gPhysicalDisplayInfoClassInfo.ctor = GetMethodIDOrDie(env,
722 gPhysicalDisplayInfoClassInfo.clazz, "<init>", "()V");
723 gPhysicalDisplayInfoClassInfo.width = GetFieldIDOrDie(env, clazz, "width", "I");
724 gPhysicalDisplayInfoClassInfo.height = GetFieldIDOrDie(env, clazz, "height", "I");
725 gPhysicalDisplayInfoClassInfo.refreshRate = GetFieldIDOrDie(env, clazz, "refreshRate", "F");
726 gPhysicalDisplayInfoClassInfo.density = GetFieldIDOrDie(env, clazz, "density", "F");
727 gPhysicalDisplayInfoClassInfo.xDpi = GetFieldIDOrDie(env, clazz, "xDpi", "F");
728 gPhysicalDisplayInfoClassInfo.yDpi = GetFieldIDOrDie(env, clazz, "yDpi", "F");
729 gPhysicalDisplayInfoClassInfo.secure = GetFieldIDOrDie(env, clazz, "secure", "Z");
730 gPhysicalDisplayInfoClassInfo.appVsyncOffsetNanos = GetFieldIDOrDie(env,
731 clazz, "appVsyncOffsetNanos", "J");
732 gPhysicalDisplayInfoClassInfo.presentationDeadlineNanos = GetFieldIDOrDie(env,
733 clazz, "presentationDeadlineNanos", "J");
Dan Stoza904f4852015-08-31 12:01:48 -0700734 gPhysicalDisplayInfoClassInfo.colorTransform = GetFieldIDOrDie(env, clazz,
735 "colorTransform", "I");
Svetoslav1376d602014-03-13 11:17:26 -0700736
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800737 jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
738 gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
739 gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
740 gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
741 gRectClassInfo.top = GetFieldIDOrDie(env, rectClazz, "top", "I");
Dan Stoza9890e3412014-05-22 16:12:54 -0700742
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800743 jclass frameStatsClazz = FindClassOrDie(env, "android/view/FrameStats");
744 jfieldID undefined_time_nano_field = GetStaticFieldIDOrDie(env,
745 frameStatsClazz, "UNDEFINED_TIME_NANO", "J");
Svetoslav1376d602014-03-13 11:17:26 -0700746 nsecs_t undefined_time_nano = env->GetStaticLongField(frameStatsClazz, undefined_time_nano_field);
747
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800748 jclass contFrameStatsClazz = FindClassOrDie(env, "android/view/WindowContentFrameStats");
749 gWindowContentFrameStatsClassInfo.init = GetMethodIDOrDie(env,
750 contFrameStatsClazz, "init", "(J[J[J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700751 gWindowContentFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
752
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800753 jclass animFrameStatsClazz = FindClassOrDie(env, "android/view/WindowAnimationFrameStats");
754 gWindowAnimationFrameStatsClassInfo.init = GetMethodIDOrDie(env,
755 animFrameStatsClazz, "init", "(J[J)V");
Svetoslav1376d602014-03-13 11:17:26 -0700756 gWindowAnimationFrameStatsClassInfo.UNDEFINED_TIME_NANO = undefined_time_nano;
757
Hangyu Kuang54ac2192016-04-25 13:22:02 -0700758 jclass hdrCapabilitiesClazz = FindClassOrDie(env, "android/view/Display$HdrCapabilities");
759 gHdrCapabilitiesClassInfo.clazz = MakeGlobalRefOrDie(env, hdrCapabilitiesClazz);
760 gHdrCapabilitiesClassInfo.ctor = GetMethodIDOrDie(env, hdrCapabilitiesClazz, "<init>",
761 "([IFFF)V");
762
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800763 return err;
764}
765
766};