Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | namespace android { |
| 32 | |
| 33 | // --------------------------------------------------------------------------- |
| 34 | |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 35 | class GLExtensions; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 36 | class GraphicBuffer; |
| 37 | |
| 38 | // --------------------------------------------------------------------------- |
| 39 | |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 40 | struct Image { |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 41 | enum { TEXTURE_2D=0, TEXTURE_EXTERNAL=1 }; |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 42 | Image() : name(-1U), image(EGL_NO_IMAGE_KHR), width(0), height(0), |
Mathias Agopian | e96aa3e | 2010-08-19 17:01:19 -0700 | [diff] [blame] | 43 | dirty(1), target(TEXTURE_2D) { } |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 44 | GLuint name; |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 45 | EGLImageKHR image; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 46 | GLuint width; |
| 47 | GLuint height; |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 48 | unsigned dirty : 1; |
| 49 | unsigned target : 1; |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct Texture : public Image { |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 53 | Texture() : Image(), NPOTAdjust(0) { } |
| 54 | GLuint potWidth; |
| 55 | GLuint potHeight; |
| 56 | GLfloat wScale; |
| 57 | GLfloat hScale; |
| 58 | unsigned NPOTAdjust : 1; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | // --------------------------------------------------------------------------- |
| 62 | |
| 63 | class TextureManager { |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 64 | const GLExtensions& mGLExtensions; |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 65 | static status_t initTexture(Image* texture, int32_t format); |
| 66 | static status_t initTexture(Texture* texture); |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 67 | static bool isSupportedYuvFormat(int format); |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 68 | static bool isYuvFormat(int format); |
| 69 | static GLenum getTextureTarget(const Image* pImage); |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 70 | public: |
| 71 | |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 72 | TextureManager(); |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 73 | |
| 74 | // load bitmap data into the active buffer |
| 75 | status_t loadTexture(Texture* texture, |
| 76 | const Region& dirty, const GGLSurface& t); |
| 77 | |
| 78 | // make active buffer an EGLImage if needed |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 79 | status_t initEglImage(Image* texture, |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 80 | EGLDisplay dpy, const sp<GraphicBuffer>& buffer); |
Mathias Agopian | f8b4b44 | 2010-06-14 21:20:00 -0700 | [diff] [blame] | 81 | |
| 82 | // activate a texture |
| 83 | static void activateTexture(const Texture& texture, bool filter); |
| 84 | |
| 85 | // deactivate a texture |
| 86 | static void deactivateTextures(); |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | // --------------------------------------------------------------------------- |
| 90 | |
| 91 | }; // namespace android |
| 92 | |
| 93 | #endif // ANDROID_TEXTURE_MANAGER_H |