19f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian/*
29f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * Copyright (C) 2010 The Android Open Source Project
39f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian *
49f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
59f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * you may not use this file except in compliance with the License.
69f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * You may obtain a copy of the License at
79f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian *
89f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
99f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian *
109f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * Unless required by applicable law or agreed to in writing, software
119f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
129f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * See the License for the specific language governing permissions and
149f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian * limitations under the License.
159f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian */
169f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
179f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#ifndef ANDROID_TEXTURE_MANAGER_H
189f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#define ANDROID_TEXTURE_MANAGER_H
199f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
209f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <stdint.h>
219f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <sys/types.h>
229f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
239f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <EGL/egl.h>
249f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <EGL/eglext.h>
259f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <GLES/gl.h>
269f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
279f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <ui/Region.h>
289f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
299f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#include <pixelflinger/pixelflinger.h>
309f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
319f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopiannamespace android {
329f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
339f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian// ---------------------------------------------------------------------------
349f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
35781953d62dc17d761e39540f0480e5ca7451cdbeMathias Agopianclass GLExtensions;
369f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopianclass GraphicBuffer;
379f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
389f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian// ---------------------------------------------------------------------------
399f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
40898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopianstruct Image {
41f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    enum { TEXTURE_2D=0, TEXTURE_EXTERNAL=1 };
42898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopian    Image() : name(-1U), image(EGL_NO_IMAGE_KHR), width(0), height(0),
43e96aa3e859cb747e241dfa2999fcd142a688ed57Mathias Agopian        dirty(1), target(TEXTURE_2D) { }
449f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    GLuint        name;
45898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopian    EGLImageKHR   image;
469f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    GLuint        width;
479f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    GLuint        height;
48f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    unsigned      dirty     : 1;
49f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    unsigned      target    : 1;
50898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopian};
51898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopian
52898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopianstruct Texture : public Image {
53f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    Texture() : Image(), NPOTAdjust(0) { }
54f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    GLuint      potWidth;
55f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    GLuint      potHeight;
56f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    GLfloat     wScale;
57f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    GLfloat     hScale;
58f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    unsigned    NPOTAdjust  : 1;
599f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian};
609f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
619f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian// ---------------------------------------------------------------------------
629f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
639f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopianclass TextureManager {
64781953d62dc17d761e39540f0480e5ca7451cdbeMathias Agopian    const GLExtensions& mGLExtensions;
65f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    static status_t initTexture(Image* texture, int32_t format);
66f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    static status_t initTexture(Texture* texture);
679f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    static bool isSupportedYuvFormat(int format);
68f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    static bool isYuvFormat(int format);
69f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    static GLenum getTextureTarget(const Image* pImage);
709f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopianpublic:
719f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
72781953d62dc17d761e39540f0480e5ca7451cdbeMathias Agopian    TextureManager();
739f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
749f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    // load bitmap data into the active buffer
759f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    status_t loadTexture(Texture* texture,
769f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian            const Region& dirty, const GGLSurface& t);
779f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
789f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian    // make active buffer an EGLImage if needed
79898c4c91be8e11b6d5388c623ae80f12ac25fd27Mathias Agopian    status_t initEglImage(Image* texture,
809f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian            EGLDisplay dpy, const sp<GraphicBuffer>& buffer);
81f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian
82f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    // activate a texture
83f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    static void activateTexture(const Texture& texture, bool filter);
84f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian
85f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    // deactivate a texture
86f8b4b4408cb864bf604608221eafa9d37323d348Mathias Agopian    static void deactivateTextures();
879f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian};
889f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
899f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian// ---------------------------------------------------------------------------
909f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
919f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian}; // namespace android
929f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian
939f2c4fd9a14ea79e4cbbd3ab8925794711a6411cMathias Agopian#endif // ANDROID_TEXTURE_MANAGER_H
94