blob: c7c14e70bb4413d8e4fdbcca78b5119b91eb0993 [file] [log] [blame]
Mathias Agopiand606de62010-05-10 20:06:11 -07001/*
2 * Copyright (C) 2010 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_TEXTURE_MANAGER_H
18#define ANDROID_TEXTURE_MANAGER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <EGL/egl.h>
24#include <EGL/eglext.h>
25#include <GLES/gl.h>
26
27#include <ui/Region.h>
28
29#include <pixelflinger/pixelflinger.h>
30
31namespace android {
32
33// ---------------------------------------------------------------------------
34
Mathias Agopian1f7bec62010-06-25 18:02:21 -070035class GLExtensions;
Mathias Agopiand606de62010-05-10 20:06:11 -070036class GraphicBuffer;
37
38// ---------------------------------------------------------------------------
39
Mathias Agopianbb641242010-05-18 17:06:55 -070040struct Image {
Mathias Agopian0a917752010-06-14 21:20:00 -070041 enum { TEXTURE_2D=0, TEXTURE_EXTERNAL=1 };
Mathias Agopianbb641242010-05-18 17:06:55 -070042 Image() : name(-1U), image(EGL_NO_IMAGE_KHR), width(0), height(0),
Mathias Agopian0a917752010-06-14 21:20:00 -070043 transform(0), dirty(1), target(TEXTURE_2D) { }
Mathias Agopiand606de62010-05-10 20:06:11 -070044 GLuint name;
Mathias Agopianbb641242010-05-18 17:06:55 -070045 EGLImageKHR image;
Mathias Agopiand606de62010-05-10 20:06:11 -070046 GLuint width;
47 GLuint height;
Mathias Agopianbb641242010-05-18 17:06:55 -070048 uint32_t transform;
Mathias Agopian0a917752010-06-14 21:20:00 -070049 unsigned dirty : 1;
50 unsigned target : 1;
Mathias Agopianbb641242010-05-18 17:06:55 -070051};
52
53struct Texture : public Image {
Mathias Agopian0a917752010-06-14 21:20:00 -070054 Texture() : Image(), NPOTAdjust(0) { }
55 GLuint potWidth;
56 GLuint potHeight;
57 GLfloat wScale;
58 GLfloat hScale;
59 unsigned NPOTAdjust : 1;
Mathias Agopiand606de62010-05-10 20:06:11 -070060};
61
62// ---------------------------------------------------------------------------
63
64class TextureManager {
Mathias Agopian1f7bec62010-06-25 18:02:21 -070065 const GLExtensions& mGLExtensions;
Mathias Agopian0a917752010-06-14 21:20:00 -070066 static status_t initTexture(Image* texture, int32_t format);
67 static status_t initTexture(Texture* texture);
Mathias Agopiand606de62010-05-10 20:06:11 -070068 static bool isSupportedYuvFormat(int format);
Mathias Agopian0a917752010-06-14 21:20:00 -070069 static bool isYuvFormat(int format);
70 static GLenum getTextureTarget(const Image* pImage);
Mathias Agopiand606de62010-05-10 20:06:11 -070071public:
72
Mathias Agopian1f7bec62010-06-25 18:02:21 -070073 TextureManager();
Mathias Agopiand606de62010-05-10 20:06:11 -070074
75 // load bitmap data into the active buffer
76 status_t loadTexture(Texture* texture,
77 const Region& dirty, const GGLSurface& t);
78
79 // make active buffer an EGLImage if needed
Mathias Agopianbb641242010-05-18 17:06:55 -070080 status_t initEglImage(Image* texture,
Mathias Agopiand606de62010-05-10 20:06:11 -070081 EGLDisplay dpy, const sp<GraphicBuffer>& buffer);
Mathias Agopian0a917752010-06-14 21:20:00 -070082
83 // activate a texture
84 static void activateTexture(const Texture& texture, bool filter);
85
86 // deactivate a texture
87 static void deactivateTextures();
Mathias Agopiand606de62010-05-10 20:06:11 -070088};
89
90// ---------------------------------------------------------------------------
91
92}; // namespace android
93
94#endif // ANDROID_TEXTURE_MANAGER_H