android_view_Surface.cpp revision 6158b1bf0364da1582468a98ec09d004ba99deec
1/*
2 * Copyright (C) 2007 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#include <stdio.h>
18
19#include "android_util_Binder.h"
20
21#include <ui/SurfaceComposerClient.h>
22#include <ui/Region.h>
23#include <ui/Rect.h>
24
25#include <SkCanvas.h>
26#include <SkBitmap.h>
27#include <SkRegion.h>
28
29#include "jni.h"
30#include <android_runtime/AndroidRuntime.h>
31#include <utils/misc.h>
32
33
34// ----------------------------------------------------------------------------
35
36namespace android {
37
38// ----------------------------------------------------------------------------
39
40static const char* const OutOfResourcesException =
41    "android/view/Surface$OutOfResourcesException";
42
43struct sso_t {
44    jfieldID client;
45};
46static sso_t sso;
47
48struct so_t {
49    jfieldID surfaceControl;
50    jfieldID surface;
51    jfieldID saveCount;
52    jfieldID canvas;
53};
54static so_t so;
55
56struct ro_t {
57    jfieldID l;
58    jfieldID t;
59    jfieldID r;
60    jfieldID b;
61};
62static ro_t ro;
63
64struct po_t {
65    jfieldID x;
66    jfieldID y;
67};
68static po_t po;
69
70struct co_t {
71    jfieldID surfaceFormat;
72};
73static co_t co;
74
75struct no_t {
76    jfieldID native_canvas;
77    jfieldID native_region;
78    jfieldID native_parcel;
79};
80static no_t no;
81
82
83static __attribute__((noinline))
84void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
85{
86    if (!env->ExceptionOccurred()) {
87        jclass npeClazz = env->FindClass(exc);
88        env->ThrowNew(npeClazz, msg);
89    }
90}
91
92// ----------------------------------------------------------------------------
93// ----------------------------------------------------------------------------
94// ----------------------------------------------------------------------------
95
96static void SurfaceSession_init(JNIEnv* env, jobject clazz)
97{
98    sp<SurfaceComposerClient> client = new SurfaceComposerClient;
99    client->incStrong(clazz);
100    env->SetIntField(clazz, sso.client, (int)client.get());
101}
102
103static void SurfaceSession_destroy(JNIEnv* env, jobject clazz)
104{
105    SurfaceComposerClient* client =
106            (SurfaceComposerClient*)env->GetIntField(clazz, sso.client);
107    if (client != 0) {
108        client->decStrong(clazz);
109        env->SetIntField(clazz, sso.client, 0);
110    }
111}
112
113static void SurfaceSession_kill(JNIEnv* env, jobject clazz)
114{
115    SurfaceComposerClient* client =
116            (SurfaceComposerClient*)env->GetIntField(clazz, sso.client);
117    if (client != 0) {
118        client->dispose();
119        client->decStrong(clazz);
120        env->SetIntField(clazz, sso.client, 0);
121    }
122}
123
124// ----------------------------------------------------------------------------
125
126static sp<SurfaceControl> getSurfaceControl(JNIEnv* env, jobject clazz)
127{
128    SurfaceControl* const p =
129        (SurfaceControl*)env->GetIntField(clazz, so.surfaceControl);
130    return sp<SurfaceControl>(p);
131}
132
133static void setSurfaceControl(JNIEnv* env, jobject clazz,
134        const sp<SurfaceControl>& surface)
135{
136    SurfaceControl* const p =
137        (SurfaceControl*)env->GetIntField(clazz, so.surfaceControl);
138    if (surface.get()) {
139        surface->incStrong(clazz);
140    }
141    if (p) {
142        p->decStrong(clazz);
143    }
144    env->SetIntField(clazz, so.surfaceControl, (int)surface.get());
145}
146
147static sp<Surface> getSurface(JNIEnv* env, jobject clazz)
148{
149    sp<Surface> result((Surface*)env->GetIntField(clazz, so.surface));
150    if (result == 0) {
151        /*
152         * if this method is called from the WindowManager's process, it means
153         * the client is is not remote, and therefore is allowed to have
154         * a Surface (data), so we create it here.
155         * If we don't have a SurfaceControl, it means we're in a different
156         * process.
157         */
158
159        SurfaceControl* const control =
160            (SurfaceControl*)env->GetIntField(clazz, so.surfaceControl);
161        if (control) {
162            result = control->getSurface();
163            if (result != 0) {
164                result->incStrong(clazz);
165                env->SetIntField(clazz, so.surface, (int)result.get());
166            }
167        }
168    }
169    return result;
170}
171
172static void setSurface(JNIEnv* env, jobject clazz, const sp<Surface>& surface)
173{
174    Surface* const p = (Surface*)env->GetIntField(clazz, so.surface);
175    if (surface.get()) {
176        surface->incStrong(clazz);
177    }
178    if (p) {
179        p->decStrong(clazz);
180    }
181    env->SetIntField(clazz, so.surface, (int)surface.get());
182}
183
184// ----------------------------------------------------------------------------
185
186static void Surface_init(
187        JNIEnv* env, jobject clazz,
188        jobject session, jint pid, jint dpy, jint w, jint h, jint format, jint flags)
189{
190    if (session == NULL) {
191        doThrow(env, "java/lang/NullPointerException");
192        return;
193    }
194
195    SurfaceComposerClient* client =
196            (SurfaceComposerClient*)env->GetIntField(session, sso.client);
197
198    sp<SurfaceControl> surface(client->createSurface(pid, dpy, w, h, format, flags));
199    if (surface == 0) {
200        doThrow(env, OutOfResourcesException);
201        return;
202    }
203    setSurfaceControl(env, clazz, surface);
204}
205
206static void Surface_initParcel(JNIEnv* env, jobject clazz, jobject argParcel)
207{
208    Parcel* parcel = (Parcel*)env->GetIntField(argParcel, no.native_parcel);
209    if (parcel == NULL) {
210        doThrow(env, "java/lang/NullPointerException", NULL);
211        return;
212    }
213    sp<Surface> rhs = new Surface(*parcel);
214    setSurface(env, clazz, rhs);
215}
216
217static void Surface_clear(JNIEnv* env, jobject clazz, uintptr_t *ostack)
218{
219    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
220    if (SurfaceControl::isValid(surface)) {
221        surface->clear();
222    }
223    setSurfaceControl(env, clazz, 0);
224    setSurface(env, clazz, 0);
225}
226
227static void Surface_release(JNIEnv* env, jobject clazz, uintptr_t *ostack)
228{
229    setSurfaceControl(env, clazz, 0);
230    setSurface(env, clazz, 0);
231}
232
233static jboolean Surface_isValid(JNIEnv* env, jobject clazz)
234{
235    const sp<SurfaceControl>& surfaceControl(getSurfaceControl(env, clazz));
236    if (surfaceControl != 0) {
237        return SurfaceControl::isValid(surfaceControl) ? JNI_TRUE : JNI_FALSE;
238    }
239    const sp<Surface>& surface(getSurface(env, clazz));
240    return Surface::isValid(surface) ? JNI_TRUE : JNI_FALSE;
241}
242
243static inline SkBitmap::Config convertPixelFormat(PixelFormat format)
244{
245    /* note: if PIXEL_FORMAT_XRGB_8888 means that all alpha bytes are 0xFF, then
246        we can map to SkBitmap::kARGB_8888_Config, and optionally call
247        bitmap.setIsOpaque(true) on the resulting SkBitmap (as an accelerator)
248    */
249	switch (format) {
250    case PIXEL_FORMAT_RGBA_8888:    return SkBitmap::kARGB_8888_Config;
251    case PIXEL_FORMAT_RGBA_4444:    return SkBitmap::kARGB_4444_Config;
252	case PIXEL_FORMAT_RGB_565:		return SkBitmap::kRGB_565_Config;
253	case PIXEL_FORMAT_A_8:          return SkBitmap::kA8_Config;
254	default:                        return SkBitmap::kNo_Config;
255	}
256}
257
258static jobject Surface_lockCanvas(JNIEnv* env, jobject clazz, jobject dirtyRect)
259{
260    const sp<Surface>& surface(getSurface(env, clazz));
261    if (!Surface::isValid(surface))
262        return 0;
263
264    // get dirty region
265    Region dirtyRegion;
266    if (dirtyRect) {
267        Rect dirty;
268        dirty.left  = env->GetIntField(dirtyRect, ro.l);
269        dirty.top   = env->GetIntField(dirtyRect, ro.t);
270        dirty.right = env->GetIntField(dirtyRect, ro.r);
271        dirty.bottom= env->GetIntField(dirtyRect, ro.b);
272        if (!dirty.isEmpty()) {
273            dirtyRegion.set(dirty);
274        }
275    } else {
276        dirtyRegion.set(Rect(0x3FFF,0x3FFF));
277    }
278
279    Surface::SurfaceInfo info;
280    status_t err = surface->lock(&info, &dirtyRegion);
281    if (err < 0) {
282        const char* const exception = (err == NO_MEMORY) ?
283            OutOfResourcesException :
284            "java/lang/IllegalArgumentException";
285        doThrow(env, exception, NULL);
286        return 0;
287    }
288
289    // Associate a SkCanvas object to this surface
290    jobject canvas = env->GetObjectField(clazz, so.canvas);
291    env->SetIntField(canvas, co.surfaceFormat, info.format);
292
293    SkCanvas* nativeCanvas = (SkCanvas*)env->GetIntField(canvas, no.native_canvas);
294    SkBitmap bitmap;
295    ssize_t bpr = info.s * bytesPerPixel(info.format);
296    bitmap.setConfig(convertPixelFormat(info.format), info.w, info.h, bpr);
297    if (info.w > 0 && info.h > 0) {
298        bitmap.setPixels(info.bits);
299    } else {
300        // be safe with an empty bitmap.
301        bitmap.setPixels(NULL);
302    }
303    nativeCanvas->setBitmapDevice(bitmap);
304
305    SkRegion clipReg;
306    if (dirtyRegion.isRect()) { // very common case
307        const Rect& b(dirtyRegion.getBounds());
308        clipReg.setRect(b.left, b.top, b.right, b.bottom);
309    } else {
310        size_t count;
311        Rect const* r = dirtyRegion.getArray(&count);
312        while (count) {
313            clipReg.op(r->left, r->top, r->right, r->bottom, SkRegion::kUnion_Op);
314            r++, count--;
315        }
316    }
317
318    nativeCanvas->clipRegion(clipReg);
319
320    int saveCount = nativeCanvas->save();
321    env->SetIntField(clazz, so.saveCount, saveCount);
322
323    if (dirtyRect) {
324        const Rect& bounds(dirtyRegion.getBounds());
325        env->SetIntField(dirtyRect, ro.l, bounds.left);
326        env->SetIntField(dirtyRect, ro.t, bounds.top);
327        env->SetIntField(dirtyRect, ro.r, bounds.right);
328        env->SetIntField(dirtyRect, ro.b, bounds.bottom);
329    }
330
331	return canvas;
332}
333
334static void Surface_unlockCanvasAndPost(
335        JNIEnv* env, jobject clazz, jobject argCanvas)
336{
337    jobject canvas = env->GetObjectField(clazz, so.canvas);
338    if (canvas != argCanvas) {
339        doThrow(env, "java/lang/IllegalArgumentException", NULL);
340        return;
341    }
342
343    const sp<Surface>& surface(getSurface(env, clazz));
344    if (!Surface::isValid(surface))
345        return;
346
347    // detach the canvas from the surface
348    SkCanvas* nativeCanvas = (SkCanvas*)env->GetIntField(canvas, no.native_canvas);
349    int saveCount = env->GetIntField(clazz, so.saveCount);
350    nativeCanvas->restoreToCount(saveCount);
351    nativeCanvas->setBitmapDevice(SkBitmap());
352    env->SetIntField(clazz, so.saveCount, 0);
353
354    // unlock surface
355    status_t err = surface->unlockAndPost();
356    if (err < 0) {
357        doThrow(env, "java/lang/IllegalArgumentException", NULL);
358    }
359}
360
361static void Surface_unlockCanvas(
362        JNIEnv* env, jobject clazz, jobject argCanvas)
363{
364    // XXX: this API has been removed
365    doThrow(env, "java/lang/IllegalArgumentException", NULL);
366}
367
368static void Surface_openTransaction(
369        JNIEnv* env, jobject clazz)
370{
371    SurfaceComposerClient::openGlobalTransaction();
372}
373
374static void Surface_closeTransaction(
375        JNIEnv* env, jobject clazz)
376{
377    SurfaceComposerClient::closeGlobalTransaction();
378}
379
380static void Surface_setOrientation(
381        JNIEnv* env, jobject clazz, jint display, jint orientation, jint flags)
382{
383    int err = SurfaceComposerClient::setOrientation(display, orientation, flags);
384    if (err < 0) {
385        doThrow(env, "java/lang/IllegalArgumentException", NULL);
386    }
387}
388
389static void Surface_freezeDisplay(
390        JNIEnv* env, jobject clazz, jint display)
391{
392    int err = SurfaceComposerClient::freezeDisplay(display, 0);
393    if (err < 0) {
394        doThrow(env, "java/lang/IllegalArgumentException", NULL);
395    }
396}
397
398static void Surface_unfreezeDisplay(
399        JNIEnv* env, jobject clazz, jint display)
400{
401    int err = SurfaceComposerClient::unfreezeDisplay(display, 0);
402    if (err < 0) {
403        doThrow(env, "java/lang/IllegalArgumentException", NULL);
404    }
405}
406
407static void Surface_setLayer(
408        JNIEnv* env, jobject clazz, jint zorder)
409{
410    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
411    if (surface == 0) return;
412    status_t err = surface->setLayer(zorder);
413    if (err<0 && err!=NO_INIT)
414        doThrow(env, "java/lang/IllegalArgumentException", NULL);
415}
416
417static void Surface_setPosition(
418        JNIEnv* env, jobject clazz, jint x, jint y)
419{
420    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
421    if (surface == 0) return;
422    status_t err = surface->setPosition(x, y);
423    if (err<0 && err!=NO_INIT)
424        doThrow(env, "java/lang/IllegalArgumentException", NULL);
425}
426
427static void Surface_setSize(
428        JNIEnv* env, jobject clazz, jint w, jint h)
429{
430    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
431    if (surface == 0) return;
432    status_t err = surface->setSize(w, h);
433    if (err<0 && err!=NO_INIT)
434        doThrow(env, "java/lang/IllegalArgumentException", NULL);
435}
436
437static void Surface_hide(
438        JNIEnv* env, jobject clazz)
439{
440    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
441    if (surface == 0) return;
442    status_t err = surface->hide();
443    if (err<0 && err!=NO_INIT)
444        doThrow(env, "java/lang/IllegalArgumentException", NULL);
445}
446
447static void Surface_show(
448        JNIEnv* env, jobject clazz)
449{
450    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
451    if (surface == 0) return;
452    status_t err = surface->show();
453    if (err<0 && err!=NO_INIT)
454        doThrow(env, "java/lang/IllegalArgumentException", NULL);
455}
456
457static void Surface_freeze(
458        JNIEnv* env, jobject clazz)
459{
460    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
461    if (surface == 0) return;
462    status_t err = surface->freeze();
463    if (err<0 && err!=NO_INIT)
464        doThrow(env, "java/lang/IllegalArgumentException", NULL);
465}
466
467static void Surface_unfreeze(
468        JNIEnv* env, jobject clazz)
469{
470    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
471    if (surface == 0) return;
472    status_t err = surface->unfreeze();
473    if (err<0 && err!=NO_INIT)
474        doThrow(env, "java/lang/IllegalArgumentException", NULL);
475}
476
477static void Surface_setFlags(
478        JNIEnv* env, jobject clazz, jint flags, jint mask)
479{
480    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
481    if (surface == 0) return;
482    status_t err = surface->setFlags(flags, mask);
483    if (err<0 && err!=NO_INIT)
484        doThrow(env, "java/lang/IllegalArgumentException", NULL);
485}
486
487static void Surface_setTransparentRegion(
488        JNIEnv* env, jobject clazz, jobject argRegion)
489{
490    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
491    if (surface == 0) return;
492    SkRegion* nativeRegion = (SkRegion*)env->GetIntField(argRegion, no.native_region);
493
494    const SkIRect& b(nativeRegion->getBounds());
495    Region reg(Rect(b.fLeft, b.fTop, b.fRight, b.fBottom));
496    if (nativeRegion->isComplex()) {
497        SkRegion::Iterator it(*nativeRegion);
498        while (!it.done()) {
499            const SkIRect& r(it.rect());
500            reg.addRectUnchecked(r.fLeft, r.fTop, r.fRight, r.fBottom);
501            it.next();
502        }
503    }
504
505    status_t err = surface->setTransparentRegionHint(reg);
506    if (err<0 && err!=NO_INIT)
507        doThrow(env, "java/lang/IllegalArgumentException", NULL);
508}
509
510static void Surface_setAlpha(
511        JNIEnv* env, jobject clazz, jfloat alpha)
512{
513    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
514    if (surface == 0) return;
515    status_t err = surface->setAlpha(alpha);
516    if (err<0 && err!=NO_INIT)
517        doThrow(env, "java/lang/IllegalArgumentException", NULL);
518}
519
520static void Surface_setMatrix(
521        JNIEnv* env, jobject clazz,
522        jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy)
523{
524    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
525    if (surface == 0) return;
526    status_t err = surface->setMatrix(dsdx, dtdx, dsdy, dtdy);
527    if (err<0 && err!=NO_INIT)
528        doThrow(env, "java/lang/IllegalArgumentException", NULL);
529}
530
531static void Surface_setFreezeTint(
532        JNIEnv* env, jobject clazz,
533        jint tint)
534{
535    const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
536    if (surface == 0) return;
537    status_t err = surface->setFreezeTint(tint);
538    if (err<0 && err!=NO_INIT)
539        doThrow(env, "java/lang/IllegalArgumentException", NULL);
540}
541
542// ----------------------------------------------------------------------------
543
544static void Surface_copyFrom(
545        JNIEnv* env, jobject clazz, jobject other)
546{
547    if (clazz == other)
548        return;
549
550    if (other == NULL) {
551        doThrow(env, "java/lang/NullPointerException", NULL);
552        return;
553    }
554
555    /*
556     * This is used by the WindowManagerService just after constructing
557     * a Surface and is necessary for returning the Surface reference to
558     * the caller. At this point, we should only have a SurfaceControl.
559     */
560
561    const sp<SurfaceControl>& surface = getSurfaceControl(env, clazz);
562    const sp<SurfaceControl>& rhs = getSurfaceControl(env, other);
563    if (!SurfaceControl::isSameSurface(surface, rhs)) {
564        // we reassign the surface only if it's a different one
565        // otherwise we would loose our client-side state.
566        setSurfaceControl(env, clazz, rhs);
567    }
568}
569
570static void Surface_readFromParcel(
571        JNIEnv* env, jobject clazz, jobject argParcel)
572{
573    Parcel* parcel = (Parcel*)env->GetIntField( argParcel, no.native_parcel);
574    if (parcel == NULL) {
575        doThrow(env, "java/lang/NullPointerException", NULL);
576        return;
577    }
578
579    const sp<Surface>& control(getSurface(env, clazz));
580    sp<Surface> rhs = new Surface(*parcel);
581    if (!Surface::isSameSurface(control, rhs)) {
582        // we reassign the surface only if it's a different one
583        // otherwise we would loose our client-side state.
584        setSurface(env, clazz, rhs);
585    }
586}
587
588static void Surface_writeToParcel(
589        JNIEnv* env, jobject clazz, jobject argParcel, jint flags)
590{
591    Parcel* parcel = (Parcel*)env->GetIntField(
592            argParcel, no.native_parcel);
593
594    if (parcel == NULL) {
595        doThrow(env, "java/lang/NullPointerException", NULL);
596        return;
597    }
598
599    const sp<SurfaceControl>& control(getSurfaceControl(env, clazz));
600    SurfaceControl::writeSurfaceToParcel(control, parcel);
601}
602
603// ----------------------------------------------------------------------------
604// ----------------------------------------------------------------------------
605// ----------------------------------------------------------------------------
606
607const char* const kSurfaceSessionClassPathName = "android/view/SurfaceSession";
608const char* const kSurfaceClassPathName = "android/view/Surface";
609static void nativeClassInit(JNIEnv* env, jclass clazz);
610
611static JNINativeMethod gSurfaceSessionMethods[] = {
612	{"init",     "()V",  (void*)SurfaceSession_init },
613	{"destroy",  "()V",  (void*)SurfaceSession_destroy },
614    {"kill",     "()V",  (void*)SurfaceSession_kill },
615};
616
617static JNINativeMethod gSurfaceMethods[] = {
618    {"nativeClassInit",     "()V",  (void*)nativeClassInit },
619    {"init",                "(Landroid/view/SurfaceSession;IIIIII)V",  (void*)Surface_init },
620    {"init",                "(Landroid/os/Parcel;)V",  (void*)Surface_initParcel },
621    {"clear",               "()V",  (void*)Surface_clear },
622    {"release",             "()V",  (void*)Surface_release },
623	{"copyFrom",            "(Landroid/view/Surface;)V",  (void*)Surface_copyFrom },
624	{"isValid",             "()Z",  (void*)Surface_isValid },
625	{"lockCanvasNative",    "(Landroid/graphics/Rect;)Landroid/graphics/Canvas;",  (void*)Surface_lockCanvas },
626	{"unlockCanvasAndPost", "(Landroid/graphics/Canvas;)V", (void*)Surface_unlockCanvasAndPost },
627	{"unlockCanvas",        "(Landroid/graphics/Canvas;)V", (void*)Surface_unlockCanvas },
628	{"openTransaction",     "()V",  (void*)Surface_openTransaction },
629    {"closeTransaction",    "()V",  (void*)Surface_closeTransaction },
630    {"setOrientation",      "(III)V", (void*)Surface_setOrientation },
631    {"freezeDisplay",       "(I)V", (void*)Surface_freezeDisplay },
632    {"unfreezeDisplay",     "(I)V", (void*)Surface_unfreezeDisplay },
633    {"setLayer",            "(I)V", (void*)Surface_setLayer },
634	{"setPosition",         "(II)V",(void*)Surface_setPosition },
635	{"setSize",             "(II)V",(void*)Surface_setSize },
636	{"hide",                "()V",  (void*)Surface_hide },
637	{"show",                "()V",  (void*)Surface_show },
638	{"freeze",              "()V",  (void*)Surface_freeze },
639	{"unfreeze",            "()V",  (void*)Surface_unfreeze },
640	{"setFlags",            "(II)V",(void*)Surface_setFlags },
641	{"setTransparentRegionHint","(Landroid/graphics/Region;)V", (void*)Surface_setTransparentRegion },
642	{"setAlpha",            "(F)V", (void*)Surface_setAlpha },
643	{"setMatrix",           "(FFFF)V",  (void*)Surface_setMatrix },
644	{"setFreezeTint",       "(I)V",  (void*)Surface_setFreezeTint },
645	{"readFromParcel",      "(Landroid/os/Parcel;)V", (void*)Surface_readFromParcel },
646	{"writeToParcel",       "(Landroid/os/Parcel;I)V", (void*)Surface_writeToParcel },
647};
648
649void nativeClassInit(JNIEnv* env, jclass clazz)
650{
651    so.surface = env->GetFieldID(clazz, "mSurface", "I");
652    so.surfaceControl = env->GetFieldID(clazz, "mSurfaceControl", "I");
653	so.saveCount = env->GetFieldID(clazz, "mSaveCount", "I");
654	so.canvas    = env->GetFieldID(clazz, "mCanvas", "Landroid/graphics/Canvas;");
655
656    jclass surfaceSession = env->FindClass("android/view/SurfaceSession");
657 	sso.client = env->GetFieldID(surfaceSession, "mClient", "I");
658
659    jclass canvas = env->FindClass("android/graphics/Canvas");
660    no.native_canvas = env->GetFieldID(canvas, "mNativeCanvas", "I");
661    co.surfaceFormat = env->GetFieldID(canvas, "mSurfaceFormat", "I");
662
663    jclass region = env->FindClass("android/graphics/Region");
664    no.native_region = env->GetFieldID(region, "mNativeRegion", "I");
665
666    jclass parcel = env->FindClass("android/os/Parcel");
667    no.native_parcel = env->GetFieldID(parcel, "mObject", "I");
668
669    jclass rect = env->FindClass("android/graphics/Rect");
670    ro.l = env->GetFieldID(rect, "left", "I");
671    ro.t = env->GetFieldID(rect, "top", "I");
672    ro.r = env->GetFieldID(rect, "right", "I");
673    ro.b = env->GetFieldID(rect, "bottom", "I");
674
675    jclass point = env->FindClass("android/graphics/Point");
676    po.x = env->GetFieldID(point, "x", "I");
677    po.y = env->GetFieldID(point, "y", "I");
678}
679
680int register_android_view_Surface(JNIEnv* env)
681{
682    int err;
683    err = AndroidRuntime::registerNativeMethods(env, kSurfaceSessionClassPathName,
684            gSurfaceSessionMethods, NELEM(gSurfaceSessionMethods));
685
686    err |= AndroidRuntime::registerNativeMethods(env, kSurfaceClassPathName,
687            gSurfaceMethods, NELEM(gSurfaceMethods));
688    return err;
689}
690
691};
692
693