EGLObjectHandle.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. package android.opengl;
  18. /**
  19. * Base class for wrapped EGL objects.
  20. *
  21. */
  22. public abstract class EGLObjectHandle {
  23. private final long mHandle;
  24. /**
  25. * @deprecated Use {@link #EGLObjectHandle(long)} instead. Handles
  26. * on 64 bit platforms will be wider than java ints.
  27. */
  28. @Deprecated
  29. protected EGLObjectHandle(int handle) {
  30. mHandle = handle;
  31. }
  32. protected EGLObjectHandle(long handle) {
  33. mHandle = handle;
  34. }
  35. /**
  36. * @deprecated Use {@link #getNativeHandle()} instead. Handles on
  37. * 64 bit platforms will be wider than java ints.
  38. */
  39. @Deprecated
  40. public int getHandle() {
  41. if ((mHandle & 0xffffffffL) != mHandle) {
  42. throw new UnsupportedOperationException();
  43. }
  44. return (int)mHandle;
  45. }
  46. /**
  47. * Returns the native handle of the wrapped EGL object. This handle can be
  48. * cast to the corresponding native type on the native side.
  49. *
  50. * For example, EGLDisplay dpy = (EGLDisplay)handle;
  51. *
  52. * @return the native handle of the wrapped EGL object.
  53. */
  54. public long getNativeHandle() {
  55. return mHandle;
  56. }
  57. @Override
  58. public int hashCode() {
  59. /*
  60. * Based on the algorithm suggested in
  61. * http://developer.android.com/reference/java/lang/Object.html
  62. */
  63. int result = 17;
  64. result = 31 * result + (int) (mHandle ^ (mHandle >>> 32));
  65. return result;
  66. }
  67. }