| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* libs/opengles/surface.cpp | 
 | 2 | ** | 
 | 3 | ** Copyright 2006, 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 | #include <stdio.h> | 
 | 19 | #include <stdlib.h> | 
 | 20 | #include "TokenManager.h" | 
 | 21 |  | 
 | 22 | namespace android { | 
 | 23 | // ---------------------------------------------------------------------------- | 
 | 24 |  | 
 | 25 | TokenManager::TokenManager() | 
 | 26 | { | 
 | 27 |     // token 0 is always reserved | 
 | 28 |     mTokenizer.reserve(0); | 
 | 29 | } | 
 | 30 |  | 
 | 31 | TokenManager::~TokenManager() | 
 | 32 | { | 
 | 33 | } | 
 | 34 |  | 
 | 35 | status_t TokenManager::getToken(GLsizei n, GLuint *tokens) | 
 | 36 | { | 
 | 37 |     Mutex::Autolock _l(mLock); | 
 | 38 |     for (GLsizei i=0 ; i<n ; i++) | 
 | 39 |         *tokens++ = mTokenizer.acquire(); | 
 | 40 |     return NO_ERROR; | 
 | 41 | } | 
 | 42 |  | 
 | 43 | void TokenManager::recycleTokens(GLsizei n, const GLuint *tokens) | 
 | 44 | { | 
 | 45 |     Mutex::Autolock _l(mLock); | 
 | 46 |     for (int i=0 ; i<n ; i++) { | 
 | 47 |         const GLuint token = *tokens++; | 
 | 48 |         if (token) { | 
 | 49 |             mTokenizer.release(token); | 
 | 50 |         } | 
 | 51 |     } | 
 | 52 | } | 
 | 53 |  | 
 | 54 | bool TokenManager::isTokenValid(GLuint token) const | 
 | 55 | { | 
 | 56 |     Mutex::Autolock _l(mLock); | 
 | 57 |     return mTokenizer.isAcquired(token); | 
 | 58 | } | 
 | 59 |  | 
 | 60 | // ---------------------------------------------------------------------------- | 
 | 61 | }; // namespace android | 
 | 62 |  |