| Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 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 | |
| 18 | package android.opengl; |
| 19 | |
| 20 | /** |
| Thomas Tafertshofer | 9b18b51 | 2012-07-12 15:58:07 -0700 | [diff] [blame] | 21 | * Base class for wrapped EGL objects. |
| 22 | * |
| Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 23 | */ |
| 24 | public abstract class EGLObjectHandle { |
| Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 25 | private final long mHandle; |
| Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 26 | |
| Narayan Kamath | 1801b18 | 2014-02-27 14:09:53 +0000 | [diff] [blame] | 27 | /** |
| Narayan Kamath | 80009c0 | 2014-02-28 14:00:10 +0000 | [diff] [blame] | 28 | * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles |
| Narayan Kamath | 1801b18 | 2014-02-27 14:09:53 +0000 | [diff] [blame] | 29 | * on 64 bit platforms will be wider than java ints. |
| 30 | */ |
| 31 | @Deprecated |
| Thomas Tafertshofer | 9b18b51 | 2012-07-12 15:58:07 -0700 | [diff] [blame] | 32 | protected EGLObjectHandle(int handle) { |
| Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 33 | mHandle = handle; |
| 34 | } |
| Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 35 | protected EGLObjectHandle(long handle) { |
| 36 | mHandle = handle; |
| 37 | } |
| Narayan Kamath | 1801b18 | 2014-02-27 14:09:53 +0000 | [diff] [blame] | 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 | } |
| Thomas Tafertshofer | 9b18b51 | 2012-07-12 15:58:07 -0700 | [diff] [blame] | 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 | */ |
| Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 57 | public long getNativeHandle() { |
| 58 | return mHandle; |
| 59 | } |
| Thomas Tafertshofer | 9b18b51 | 2012-07-12 15:58:07 -0700 | [diff] [blame] | 60 | @Override |
| 61 | public int hashCode() { |
| Ashok Bhat | 84bbeb9 | 2014-02-24 10:06:55 +0000 | [diff] [blame] | 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; |
| Thomas Tafertshofer | 9b18b51 | 2012-07-12 15:58:07 -0700 | [diff] [blame] | 69 | } |
| Thomas Tafertshofer | 6b1e838 | 2012-07-03 13:37:35 -0700 | [diff] [blame] | 70 | } |