1 #ifndef egl_Image_hpp
\r
2 #define egl_Image_hpp
\r
4 #include "Renderer/Surface.hpp"
\r
6 #if defined(__ANDROID__)
\r
7 #include <hardware/gralloc.h>
\r
8 #include <system/window.h>
\r
12 #include "../../Common/DebugAndroid.hpp"
\r
19 // Types common between gl.h and gl2.h
\r
20 // We can't include either header in EGL
\r
21 typedef unsigned int GLenum;
\r
23 typedef int GLsizei;
\r
27 class Image : public sw::Surface
\r
30 Image(sw::Resource *resource, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, sw::Format internalFormat)
\r
31 : width(width), height(height), format(format), type(type), internalFormat(internalFormat), depth(depth)
\r
32 , sw::Surface(resource, width, height, depth, internalFormat, true, true)
\r
36 #if defined(__ANDROID__)
\r
42 Image(sw::Resource *resource, int width, int height, int depth, sw::Format internalFormat, bool lockable, bool renderTarget)
\r
43 : width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(depth)
\r
44 , sw::Surface(resource, width, height, depth, internalFormat, lockable, renderTarget)
\r
48 #if defined(__ANDROID__)
\r
54 GLsizei getWidth() const
\r
59 GLsizei getHeight() const
\r
64 int getDepth() const
\r
66 // FIXME: add member if the depth dimension (for 3D textures or 2D testure arrays)
\r
67 // and multi sample depth are ever simultaneously required.
\r
71 GLenum getFormat() const
\r
76 GLenum getType() const
\r
81 sw::Format getInternalFormat() const
\r
83 return internalFormat;
\r
86 bool isShared() const
\r
96 void *lock(unsigned int left, unsigned int top, sw::Lock lock)
\r
98 #if defined(__ANDROID__)
\r
99 if(nativeBuffer) // Lock the buffer from ANativeWindowBuffer
\r
101 return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
\r
105 return lockExternal(left, top, 0, lock, sw::PUBLIC);
\r
108 unsigned int getPitch() const
\r
110 return getExternalPitchB();
\r
115 #if defined(__ANDROID__)
\r
116 if(nativeBuffer) // Unlock the buffer from ANativeWindowBuffer
\r
118 return unlockNativeBuffer();
\r
125 virtual void addRef() = 0;
\r
126 virtual void release() = 0;
\r
127 virtual void unbind(const Texture *parent) = 0; // Break parent ownership and release
\r
129 void destroyShared() // Release a shared image
\r
131 #if defined(__ANDROID__)
\r
134 nativeBuffer->common.decRef(&nativeBuffer->common);
\r
143 virtual void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLint unpackAlignment, const void *input) = 0;
\r
144 virtual void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels) = 0;
\r
146 #if defined(__ANDROID__)
\r
147 void setNativeBuffer(ANativeWindowBuffer* buffer)
\r
149 nativeBuffer = buffer;
\r
150 nativeBuffer->common.incRef(&nativeBuffer->common);
\r
153 virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
\r
155 if(nativeBuffer) // Lock the buffer from ANativeWindowBuffer
\r
157 return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
\r
159 return sw::Surface::lockInternal(x, y, z, lock, client);
\r
162 virtual void unlockInternal()
\r
164 if(nativeBuffer) // Unlock the buffer from ANativeWindowBuffer
\r
166 return unlockNativeBuffer();
\r
168 return sw::Surface::unlockInternal();
\r
177 const GLsizei width;
\r
178 const GLsizei height;
\r
179 const GLenum format;
\r
181 const sw::Format internalFormat;
\r
184 bool shared; // Used as an EGLImage
\r
186 #if defined(__ANDROID__)
\r
187 ANativeWindowBuffer *nativeBuffer;
\r
188 gralloc_module_t const *gralloc;
\r
192 hw_module_t const *module;
\r
193 hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
\r
194 gralloc = reinterpret_cast<gralloc_module_t const*>(module);
\r
197 void* lockNativeBuffer(int usage)
\r
205 gralloc->lock(gralloc, nativeBuffer->handle, usage, 0, 0, nativeBuffer->width, nativeBuffer->height, &buffer);
\r
209 void unlockNativeBuffer()
\r
216 gralloc->unlock(gralloc, nativeBuffer->handle);
\r
222 #endif // egl_Image_hpp
\r