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