blob: f961eb7a4894dfd09c94bee70fc2a1fa0daed4d0 [file] [log] [blame]
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -07001/*
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/**
Thomas Tafertshofer9b18b512012-07-12 15:58:07 -070021 * Base class for wrapped EGL objects.
22 *
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070023 */
24public abstract class EGLObjectHandle {
Ashok Bhat84bbeb92014-02-24 10:06:55 +000025 private final long mHandle;
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070026
Narayan Kamath1801b182014-02-27 14:09:53 +000027 /**
Narayan Kamath80009c02014-02-28 14:00:10 +000028 * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles
Narayan Kamath1801b182014-02-27 14:09:53 +000029 * on 64 bit platforms will be wider than java ints.
30 */
31 @Deprecated
Thomas Tafertshofer9b18b512012-07-12 15:58:07 -070032 protected EGLObjectHandle(int handle) {
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070033 mHandle = handle;
34 }
Ashok Bhat84bbeb92014-02-24 10:06:55 +000035 protected EGLObjectHandle(long handle) {
36 mHandle = handle;
37 }
Narayan Kamath1801b182014-02-27 14:09:53 +000038 /**
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 Tafertshofer9b18b512012-07-12 15:58:07 -070049 /**
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 Bhat84bbeb92014-02-24 10:06:55 +000057 public long getNativeHandle() {
58 return mHandle;
59 }
Thomas Tafertshofer9b18b512012-07-12 15:58:07 -070060 @Override
61 public int hashCode() {
Ashok Bhat84bbeb92014-02-24 10:06:55 +000062 /*
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 Tafertshofer9b18b512012-07-12 15:58:07 -070069 }
Thomas Tafertshofer6b1e8382012-07-03 13:37:35 -070070}