blob: 497528c76b0e9ed122f83896983bfdd29b5c44df [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2** Copyright 2006, The Android Open Source Project
3**
Mathias Agopian076b1cc2009-04-10 14:24:30 -07004** 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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08007**
Mathias Agopian076b1cc2009-04-10 14:24:30 -07008** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08009**
Mathias Agopian076b1cc2009-04-10 14:24:30 -070010** 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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080014** 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
38namespace android {
39
40// ----------------------------------------------------------------------------
41
42class EGLTextureObject
43{
44public:
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
64private:
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
74public:
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;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070084#ifdef LIBAGL_USE_GRALLOC_COPYBITS
85 int copybits_fd;
86#endif // LIBAGL_USE_GRALLOC_COPYBITS
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087};
88
89void EGLTextureObject::incStrong(const void* id) const {
90 android_atomic_inc(&mCount);
91}
92void EGLTextureObject::decStrong(const void* id) const {
93 if (android_atomic_dec(&mCount) == 1) {
94 delete this;
95 }
96}
97uint32_t EGLTextureObject::getStrongCount() const {
98 return mCount;
99}
100size_t EGLTextureObject::size() const {
101 return mSize;
102}
103
104// ----------------------------------------------------------------------------
105
106class EGLSurfaceManager : public TokenManager
107{
108public:
109 EGLSurfaceManager();
110 ~EGLSurfaceManager();
111
112 // protocol for sp<>
113 inline void incStrong(const void* id) const;
114 inline void decStrong(const void* id) const;
115 typedef void weakref_type;
116
117 sp<EGLTextureObject> createTexture(GLuint name);
118 sp<EGLTextureObject> removeTexture(GLuint name);
119 sp<EGLTextureObject> replaceTexture(GLuint name);
120 void deleteTextures(GLsizei n, const GLuint *tokens);
121 sp<EGLTextureObject> texture(GLuint name);
122
123private:
124 mutable int32_t mCount;
125 mutable Mutex mLock;
126 KeyedVector< GLuint, sp<EGLTextureObject> > mTextures;
127};
128
129void EGLSurfaceManager::incStrong(const void* id) const {
130 android_atomic_inc(&mCount);
131}
132void EGLSurfaceManager::decStrong(const void* id) const {
133 if (android_atomic_dec(&mCount) == 1) {
134 delete this;
135 }
136}
137
138
139// ----------------------------------------------------------------------------
140}; // namespace android
141
142#endif // ANDROID_OPENGLES_SURFACE_H
143