TextureObjectManager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. ** Copyright 2006, 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. #ifndef ANDROID_OPENGLES_SURFACE_H
  17. #define ANDROID_OPENGLES_SURFACE_H
  18. #include <stdint.h>
  19. #include <stddef.h>
  20. #include <sys/types.h>
  21. #include <utils/Atomic.h>
  22. #include <utils/threads.h>
  23. #include <utils/RefBase.h>
  24. #include <utils/KeyedVector.h>
  25. #include <utils/Errors.h>
  26. #include <private/pixelflinger/ggl_context.h>
  27. #include <GLES/gl.h>
  28. #include <EGL/egl.h>
  29. #include <EGL/eglext.h>
  30. #include "Tokenizer.h"
  31. #include "TokenManager.h"
  32. namespace android {
  33. // ----------------------------------------------------------------------------
  34. class EGLTextureObject : public LightRefBase<EGLTextureObject>
  35. {
  36. public:
  37. EGLTextureObject();
  38. ~EGLTextureObject();
  39. status_t setSurface(GGLSurface const* s);
  40. status_t setImage(ANativeWindowBuffer* buffer);
  41. void setImageBits(void* vaddr) { surface.data = (GGLubyte*)vaddr; }
  42. status_t reallocate(GLint level,
  43. int w, int h, int s,
  44. int format, int compressedFormat, int bpr);
  45. inline size_t size() const { return mSize; }
  46. const GGLSurface& mip(int lod) const;
  47. GGLSurface& editMip(int lod);
  48. bool hasMipmaps() const { return mMipmaps!=0; }
  49. bool isComplete() const { return mIsComplete; }
  50. void copyParameters(const sp<EGLTextureObject>& old);
  51. private:
  52. status_t allocateMipmaps();
  53. void freeMipmaps();
  54. void init();
  55. size_t mSize;
  56. GGLSurface *mMipmaps;
  57. int mNumExtraLod;
  58. bool mIsComplete;
  59. public:
  60. GGLSurface surface;
  61. GLenum wraps;
  62. GLenum wrapt;
  63. GLenum min_filter;
  64. GLenum mag_filter;
  65. GLenum internalformat;
  66. GLint crop_rect[4];
  67. GLint generate_mipmap;
  68. GLint direct;
  69. ANativeWindowBuffer* buffer;
  70. };
  71. // ----------------------------------------------------------------------------
  72. class EGLSurfaceManager :
  73. public LightRefBase<EGLSurfaceManager>,
  74. public TokenManager
  75. {
  76. public:
  77. EGLSurfaceManager();
  78. ~EGLSurfaceManager();
  79. sp<EGLTextureObject> createTexture(GLuint name);
  80. sp<EGLTextureObject> removeTexture(GLuint name);
  81. sp<EGLTextureObject> replaceTexture(GLuint name);
  82. void deleteTextures(GLsizei n, const GLuint *tokens);
  83. sp<EGLTextureObject> texture(GLuint name);
  84. private:
  85. mutable Mutex mLock;
  86. KeyedVector< GLuint, sp<EGLTextureObject> > mTextures;
  87. };
  88. // ----------------------------------------------------------------------------
  89. }; // namespace android
  90. #endif // ANDROID_OPENGLES_SURFACE_H