166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer/*
266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** Copyright 2012, The Android Open Source Project
466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** Licensed under the Apache License, Version 2.0 (the "License");
666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** you may not use this file except in compliance with the License.
766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** You may obtain a copy of the License at
866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**     http://www.apache.org/licenses/LICENSE-2.0
1066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer**
1166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** Unless required by applicable law or agreed to in writing, software
1266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** distributed under the License is distributed on an "AS IS" BASIS,
1366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** See the License for the specific language governing permissions and
1566a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer** limitations under the License.
1666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer*/
1766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
1866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferpackage android.opengl;
1966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
2066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer/**
21c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * Base class for wrapped EGL objects.
22c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer *
2366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer */
2466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshoferpublic abstract class EGLObjectHandle {
25ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    private final long mHandle;
2666a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer
27a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath    /**
28622b6b28f20498b410031c614cd0806b8fb50728Narayan Kamath     * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles
29a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     *     on 64 bit platforms will be wider than java ints.
30a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     */
31a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath    @Deprecated
32c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer    protected EGLObjectHandle(int handle) {
3366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer        mHandle = handle;
3466a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
35ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    protected EGLObjectHandle(long handle) {
36ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        mHandle = handle;
37ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
38c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer    /**
39a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     * @deprecated Use {@link #getNativeHandle()} instead. Handles on
40a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     *     64 bit platforms will be wider than java ints.
41c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer     */
42a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath    @Deprecated
4366a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    public int getHandle() {
44ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        if ((mHandle & 0xffffffffL) != mHandle) {
45ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat            throw new UnsupportedOperationException();
46ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        }
47ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        return (int)mHandle;
4866a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer    }
49ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    /**
50a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     * Returns the native handle of the wrapped EGL object. This handle can be
51a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     * cast to the corresponding native type on the native side.
52a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     *
53a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     * For example, EGLDisplay dpy = (EGLDisplay)handle;
54a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     *
55a90086a914f2fad9686e8e3d23dcdf65f38360ebNarayan Kamath     * @return the native handle of the wrapped EGL object.
56ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat     */
57ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    public long getNativeHandle() {
58ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        return mHandle;
59ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat    }
60c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer    @Override
61c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer    public int hashCode() {
62ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        /*
63ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat         * Based on the algorithm suggested in
64ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat         * http://developer.android.com/reference/java/lang/Object.html
65ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat         */
66ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        int result = 17;
67ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        result = 31 * result + (int) (mHandle ^ (mHandle >>> 32));
68ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat        return result;
69c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer    }
7066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer}
71