TextureObjectManager.h revision 8d2e83b9f44c7f2207a312fcfda8eb3a4c26745f
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#include <EGL/egl.h>
34#include <EGL/eglext.h>
35
36#include "Tokenizer.h"
37#include "TokenManager.h"
38
39
40namespace android {
41
42// ----------------------------------------------------------------------------
43
44class EGLTextureObject : public LightRefBase<EGLTextureObject>
45{
46public:
47                    EGLTextureObject();
48                   ~EGLTextureObject();
49
50    status_t    setSurface(GGLSurface const* s);
51    status_t    setImage(android_native_buffer_t* buffer);
52    void        setImageBits(void* vaddr) { surface.data = (GGLubyte*)vaddr; }
53
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 { return mSize; }
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
64private:
65        status_t        allocateMipmaps();
66            void        freeMipmaps();
67            void        init();
68    size_t              mSize;
69    GGLSurface          *mMipmaps;
70    int                 mNumExtraLod;
71    bool                mIsComplete;
72
73public:
74    GGLSurface          surface;
75    GLenum              wraps;
76    GLenum              wrapt;
77    GLenum              min_filter;
78    GLenum              mag_filter;
79    GLenum              internalformat;
80    GLint               crop_rect[4];
81    GLint               generate_mipmap;
82    GLint               direct;
83#ifdef LIBAGL_USE_GRALLOC_COPYBITS
84    bool                try_copybit;
85#endif // LIBAGL_USE_GRALLOC_COPYBITS
86    android_native_buffer_t* buffer;
87};
88
89// ----------------------------------------------------------------------------
90
91class EGLSurfaceManager :
92    public LightRefBase<EGLSurfaceManager>,
93    public TokenManager
94{
95public:
96                EGLSurfaceManager();
97                ~EGLSurfaceManager();
98
99    sp<EGLTextureObject>    createTexture(GLuint name);
100    sp<EGLTextureObject>    removeTexture(GLuint name);
101    sp<EGLTextureObject>    replaceTexture(GLuint name);
102    void                    deleteTextures(GLsizei n, const GLuint *tokens);
103    sp<EGLTextureObject>    texture(GLuint name);
104
105private:
106    mutable Mutex                               mLock;
107    KeyedVector< GLuint, sp<EGLTextureObject> > mTextures;
108};
109
110// ----------------------------------------------------------------------------
111}; // namespace android
112
113#endif // ANDROID_OPENGLES_SURFACE_H
114
115