1 /* 2 * Copyright (C) 2006 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 package android.view; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 21 /** 22 * An instance of this class represents a connection to the surface 23 * flinger, from which you can create one or more Surface instances that will 24 * be composited to the screen. 25 * {@hide} 26 */ 27 public final class SurfaceSession { 28 // Note: This field is accessed by native code. 29 @UnsupportedAppUsage 30 private long mNativeClient; // SurfaceComposerClient* 31 nativeCreate()32 private static native long nativeCreate(); nativeDestroy(long ptr)33 private static native void nativeDestroy(long ptr); nativeKill(long ptr)34 private static native void nativeKill(long ptr); 35 36 /** Create a new connection with the surface flinger. */ 37 @UnsupportedAppUsage SurfaceSession()38 public SurfaceSession() { 39 mNativeClient = nativeCreate(); 40 } 41 42 /* no user serviceable parts here ... */ 43 @Override finalize()44 protected void finalize() throws Throwable { 45 try { 46 if (mNativeClient != 0) { 47 nativeDestroy(mNativeClient); 48 } 49 } finally { 50 super.finalize(); 51 } 52 } 53 54 /** 55 * Forcibly detach native resources associated with this object. 56 * Unlike destroy(), after this call any surfaces that were created 57 * from the session will no longer work. 58 */ 59 @UnsupportedAppUsage kill()60 public void kill() { 61 nativeKill(mNativeClient); 62 } 63 } 64 65