16b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/*
26b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
36b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** Copyright 2012, The Android Open Source Project
46b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
56b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** Licensed under the Apache License, Version 2.0 (the "License");
66b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** you may not use this file except in compliance with the License.
76b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** You may obtain a copy of the License at
86b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
96b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**     http://www.apache.org/licenses/LICENSE-2.0
106b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer**
116b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** Unless required by applicable law or agreed to in writing, software
126b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** distributed under the License is distributed on an "AS IS" BASIS,
136b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
146b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** See the License for the specific language governing permissions and
156b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer** limitations under the License.
166b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer*/
176b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
186b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferpackage android.opengl;
196b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
206b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer/**
219b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer * Base class for wrapped EGL objects.
229b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer *
236b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer */
246b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshoferpublic abstract class EGLObjectHandle {
2584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    private final long mHandle;
266b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer
271801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath    /**
2880009c029800fd343012ce55648ef9a21c139527Narayan Kamath     * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles
291801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     *     on 64 bit platforms will be wider than java ints.
301801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     */
311801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath    @Deprecated
329b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer    protected EGLObjectHandle(int handle) {
336b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer        mHandle = handle;
346b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
3584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    protected EGLObjectHandle(long handle) {
3684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        mHandle = handle;
3784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    }
389b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer    /**
391801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     * @deprecated Use {@link #getNativeHandle()} instead. Handles on
401801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     *     64 bit platforms will be wider than java ints.
419b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer     */
421801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath    @Deprecated
436b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    public int getHandle() {
4484bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        if ((mHandle & 0xffffffffL) != mHandle) {
4584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat            throw new UnsupportedOperationException();
4684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        }
4784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        return (int)mHandle;
486b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer    }
4984bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    /**
501801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     * Returns the native handle of the wrapped EGL object. This handle can be
511801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     * cast to the corresponding native type on the native side.
521801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     *
531801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     * For example, EGLDisplay dpy = (EGLDisplay)handle;
541801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     *
551801b180dac364a25ef12a5af01ce0bb5a74a601Narayan Kamath     * @return the native handle of the wrapped EGL object.
5684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat     */
5784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    public long getNativeHandle() {
5884bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        return mHandle;
5984bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat    }
609b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer    @Override
619b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer    public int hashCode() {
6284bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        /*
6384bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat         * Based on the algorithm suggested in
6484bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat         * http://developer.android.com/reference/java/lang/Object.html
6584bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat         */
6684bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        int result = 17;
6784bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        result = 31 * result + (int) (mHandle ^ (mHandle >>> 32));
6884bbeb9e0c9c185a22d4882b79e0bc8a598642abAshok Bhat        return result;
699b18b515909354d7b48c8ebc33ec38e2c6bbdf37Thomas Tafertshofer    }
706b1e838fc16d397359f82c3a4f5700f1ed7dd910Thomas Tafertshofer}
71