blob: 29d50370eb41d55417ebdf6f37e98cc396f24aec [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>
Mathias Agopian0926f502009-05-04 14:17:04 -070033#include <EGL/android_natives.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
35#include "Tokenizer.h"
36#include "TokenManager.h"
37
38
39namespace android {
40
41// ----------------------------------------------------------------------------
42
Mathias Agopian0926f502009-05-04 14:17:04 -070043class EGLTextureObject : public LightRefBase<EGLTextureObject>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044{
45public:
46 EGLTextureObject();
47 ~EGLTextureObject();
48
Mathias Agopian0926f502009-05-04 14:17:04 -070049 status_t setSurface(GGLSurface const* s);
50 status_t setImage(android_native_buffer_t* buffer);
51 void setImageBits(void* vaddr) { surface.data = (GGLubyte*)vaddr; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 status_t reallocate(GLint level,
54 int w, int h, int s,
55 int format, int compressedFormat, int bpr);
Mathias Agopian0926f502009-05-04 14:17:04 -070056 inline size_t size() const { return mSize; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 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();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 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;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070082#ifdef LIBAGL_USE_GRALLOC_COPYBITS
83 int copybits_fd;
84#endif // LIBAGL_USE_GRALLOC_COPYBITS
Mathias Agopian0926f502009-05-04 14:17:04 -070085 android_native_buffer_t* buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086};
87
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088// ----------------------------------------------------------------------------
89
Mathias Agopian0926f502009-05-04 14:17:04 -070090class EGLSurfaceManager :
91 public LightRefBase<EGLSurfaceManager>,
92 public TokenManager
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093{
94public:
95 EGLSurfaceManager();
96 ~EGLSurfaceManager();
97
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098 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:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 mutable Mutex mLock;
106 KeyedVector< GLuint, sp<EGLTextureObject> > mTextures;
107};
108
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109// ----------------------------------------------------------------------------
110}; // namespace android
111
112#endif // ANDROID_OPENGLES_SURFACE_H
113