• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TokenManager()25 TokenManager::TokenManager()
26 {
27     // token 0 is always reserved
28     mTokenizer.reserve(0);
29 }
30 
~TokenManager()31 TokenManager::~TokenManager()
32 {
33 }
34 
getToken(GLsizei n,GLuint * tokens)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 
recycleTokens(GLsizei n,const GLuint * tokens)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 
isTokenValid(GLuint token) const54 bool TokenManager::isTokenValid(GLuint token) const
55 {
56     Mutex::Autolock _l(mLock);
57     return mTokenizer.isAcquired(token);
58 }
59 
60 // ----------------------------------------------------------------------------
61 }; // namespace android
62 
63