The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2006, The Android Open Source Project |
| 3 | ** |
| 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_OPENGLES_SURFACE_H |
| 18 | #define ANDROID_OPENGLES_SURFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <stddef.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <utils/Atomic.h> |
| 25 | #include <utils/threads.h> |
| 26 | #include <utils/RefBase.h> |
| 27 | #include <utils/KeyedVector.h> |
| 28 | #include <utils/Errors.h> |
| 29 | |
| 30 | #include <private/pixelflinger/ggl_context.h> |
| 31 | |
| 32 | #include <GLES/gl.h> |
| 33 | |
| 34 | #include "Tokenizer.h" |
| 35 | #include "TokenManager.h" |
| 36 | |
| 37 | |
| 38 | namespace android { |
| 39 | |
| 40 | // ---------------------------------------------------------------------------- |
| 41 | |
| 42 | class EGLTextureObject |
| 43 | { |
| 44 | public: |
| 45 | EGLTextureObject(); |
| 46 | ~EGLTextureObject(); |
| 47 | |
| 48 | // protocol for sp<> |
| 49 | inline void incStrong(const void* id) const; |
| 50 | inline void decStrong(const void* id) const; |
| 51 | inline uint32_t getStrongCount() const; |
| 52 | |
| 53 | status_t setSurface(GGLSurface const* s); |
| 54 | status_t reallocate(GLint level, |
| 55 | int w, int h, int s, |
| 56 | int format, int compressedFormat, int bpr); |
| 57 | inline size_t size() const; |
| 58 | const GGLSurface& mip(int lod) const; |
| 59 | GGLSurface& editMip(int lod); |
| 60 | bool hasMipmaps() const { return mMipmaps!=0; } |
| 61 | bool isComplete() const { return mIsComplete; } |
| 62 | void copyParameters(const sp<EGLTextureObject>& old); |
| 63 | |
| 64 | private: |
| 65 | status_t allocateMipmaps(); |
| 66 | void freeMipmaps(); |
| 67 | void init(); |
| 68 | mutable int32_t mCount; |
| 69 | size_t mSize; |
| 70 | GGLSurface *mMipmaps; |
| 71 | int mNumExtraLod; |
| 72 | bool mIsComplete; |
| 73 | |
| 74 | public: |
| 75 | GGLSurface surface; |
| 76 | GLenum wraps; |
| 77 | GLenum wrapt; |
| 78 | GLenum min_filter; |
| 79 | GLenum mag_filter; |
| 80 | GLenum internalformat; |
| 81 | GLint crop_rect[4]; |
| 82 | GLint generate_mipmap; |
| 83 | GLint direct; |
| 84 | }; |
| 85 | |
| 86 | void EGLTextureObject::incStrong(const void* id) const { |
| 87 | android_atomic_inc(&mCount); |
| 88 | } |
| 89 | void EGLTextureObject::decStrong(const void* id) const { |
| 90 | if (android_atomic_dec(&mCount) == 1) { |
| 91 | delete this; |
| 92 | } |
| 93 | } |
| 94 | uint32_t EGLTextureObject::getStrongCount() const { |
| 95 | return mCount; |
| 96 | } |
| 97 | size_t EGLTextureObject::size() const { |
| 98 | return mSize; |
| 99 | } |
| 100 | |
| 101 | // ---------------------------------------------------------------------------- |
| 102 | |
| 103 | class EGLSurfaceManager : public TokenManager |
| 104 | { |
| 105 | public: |
| 106 | EGLSurfaceManager(); |
| 107 | ~EGLSurfaceManager(); |
| 108 | |
| 109 | // protocol for sp<> |
| 110 | inline void incStrong(const void* id) const; |
| 111 | inline void decStrong(const void* id) const; |
| 112 | typedef void weakref_type; |
| 113 | |
| 114 | sp<EGLTextureObject> createTexture(GLuint name); |
| 115 | sp<EGLTextureObject> removeTexture(GLuint name); |
| 116 | sp<EGLTextureObject> replaceTexture(GLuint name); |
| 117 | void deleteTextures(GLsizei n, const GLuint *tokens); |
| 118 | sp<EGLTextureObject> texture(GLuint name); |
| 119 | |
| 120 | private: |
| 121 | mutable int32_t mCount; |
| 122 | mutable Mutex mLock; |
| 123 | KeyedVector< GLuint, sp<EGLTextureObject> > mTextures; |
| 124 | }; |
| 125 | |
| 126 | void EGLSurfaceManager::incStrong(const void* id) const { |
| 127 | android_atomic_inc(&mCount); |
| 128 | } |
| 129 | void EGLSurfaceManager::decStrong(const void* id) const { |
| 130 | if (android_atomic_dec(&mCount) == 1) { |
| 131 | delete this; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | |
| 136 | // ---------------------------------------------------------------------------- |
| 137 | }; // namespace android |
| 138 | |
| 139 | #endif // ANDROID_OPENGLES_SURFACE_H |
| 140 | |