EGLObjectHandle.java revision ab6fc2a86f34be455c144a2d691e94909998c959
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 27ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat // TODO Deprecate EGLObjectHandle(int) method 28c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer protected EGLObjectHandle(int handle) { 2966a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer mHandle = handle; 3066a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 31ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat // TODO Unhide the EGLObjectHandle(long) method 32ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat /** 33ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat * {@hide} 34ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat */ 35ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat protected EGLObjectHandle(long handle) { 36ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat mHandle = handle; 37ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat } 38ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat // TODO Deprecate getHandle() method in favor of getNativeHandle() 39c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer /** 40c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * Returns the native handle of the wrapped EGL object. This handle can be 41c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * cast to the corresponding native type on the native side. 42c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * 43c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * For example, EGLDisplay dpy = (EGLDisplay)handle; 44c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * 45c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer * @return the native handle of the wrapped EGL object. 46c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer */ 4766a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer public int getHandle() { 48ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat if ((mHandle & 0xffffffffL) != mHandle) { 49ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat throw new UnsupportedOperationException(); 50ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat } 51ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat return (int)mHandle; 5266a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer } 53c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer 54ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat // TODO Unhide getNativeHandle() method 55ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat /** 56ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat * {@hide} 57ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat */ 58ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat public long getNativeHandle() { 59ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat return mHandle; 60ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat } 61c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer @Override 62c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer public int hashCode() { 63ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat /* 64ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat * Based on the algorithm suggested in 65ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat * http://developer.android.com/reference/java/lang/Object.html 66ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat */ 67ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat int result = 17; 68ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat result = 31 * result + (int) (mHandle ^ (mHandle >>> 32)); 69ab6fc2a86f34be455c144a2d691e94909998c959Ashok Bhat return result; 70c5ee93e5fe2de4390ee96fb3b14c41f6ca45f5a2Thomas Tafertshofer } 7166a42db8cbfba902f72f0ace5ac448ef4bfd3951Thomas Tafertshofer} 72