1/*
2**
3** Copyright 2012, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18package android.opengl;
19
20/**
21 * Base class for wrapped EGL objects.
22 *
23 */
24public abstract class EGLObjectHandle {
25    private final long mHandle;
26
27    /**
28     * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles
29     *     on 64 bit platforms will be wider than java ints.
30     */
31    @Deprecated
32    protected EGLObjectHandle(int handle) {
33        mHandle = handle;
34    }
35    protected EGLObjectHandle(long handle) {
36        mHandle = handle;
37    }
38    /**
39     * @deprecated Use {@link #getNativeHandle()} instead. Handles on
40     *     64 bit platforms will be wider than java ints.
41     */
42    @Deprecated
43    public int getHandle() {
44        if ((mHandle & 0xffffffffL) != mHandle) {
45            throw new UnsupportedOperationException();
46        }
47        return (int)mHandle;
48    }
49    /**
50     * Returns the native handle of the wrapped EGL object. This handle can be
51     * cast to the corresponding native type on the native side.
52     *
53     * For example, EGLDisplay dpy = (EGLDisplay)handle;
54     *
55     * @return the native handle of the wrapped EGL object.
56     */
57    public long getNativeHandle() {
58        return mHandle;
59    }
60    @Override
61    public int hashCode() {
62        /*
63         * Based on the algorithm suggested in
64         * http://developer.android.com/reference/java/lang/Object.html
65         */
66        int result = 17;
67        result = 31 * result + (int) (mHandle ^ (mHandle >>> 32));
68        return result;
69    }
70}
71