Commit c8bae0b7 by Nicolas Capens

Refactor HAL to GL format conversions.

Bug 25390254 Change-Id: I434e6d319335be00204eff88f09c98b2dd4f2acc Reviewed-on: https://swiftshader-review.googlesource.com/4188Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent b3c0c739
#include <system/window.h> #include "AndroidCommon.hpp"
#include "GL/glcorearb.h"
#include "GL/glext.h" #include "../../Common/DebugAndroid.hpp"
#include "EGL/egl.h"
#include <GLES/glext.h>
#include <system/graphics.h>
#define GL_RGB565 0x8D62 #define GL_RGB565 0x8D62
#define SW_YV12_BT601 0x32315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.601 color space, studio swing #define SW_YV12_BT601 0x32315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.601 color space, studio swing
#define SW_YV12_BT709 0x48315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.709 color space, studio swing #define SW_YV12_BT709 0x48315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.709 color space, studio swing
#define SW_YV12_JFIF 0x4A315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.601 color space, full swing #define SW_YV12_JFIF 0x4A315659 // YCrCb 4:2:0 Planar, 16-byte aligned, BT.601 color space, full swing
#include "AndroidCommon.hpp" GLenum GLPixelFormatFromAndroid(int halFormat)
#include "../../Common/DebugAndroid.hpp"
#include "../../Common/GrallocAndroid.hpp"
GLenum getColorFormatFromAndroid(int format)
{ {
switch(format) switch(halFormat)
{ {
case HAL_PIXEL_FORMAT_RGBA_8888: case HAL_PIXEL_FORMAT_RGBA_8888:
return GL_RGBA; return GL_RGBA;
case HAL_PIXEL_FORMAT_RGBX_8888: case HAL_PIXEL_FORMAT_RGBX_8888:
return GL_RGB; return GL_RGB;
case HAL_PIXEL_FORMAT_RGB_888: case HAL_PIXEL_FORMAT_RGB_888:
return GL_RGB; return GL_RGB;
case HAL_PIXEL_FORMAT_BGRA_8888: case HAL_PIXEL_FORMAT_BGRA_8888:
return GL_BGRA_EXT; return GL_BGRA_EXT;
case HAL_PIXEL_FORMAT_RGB_565: case HAL_PIXEL_FORMAT_RGB_565:
return GL_RGB565; return GL_RGB565;
case HAL_PIXEL_FORMAT_YV12: case HAL_PIXEL_FORMAT_YV12:
return SW_YV12_BT601; return SW_YV12_BT601;
case HAL_PIXEL_FORMAT_BLOB: case HAL_PIXEL_FORMAT_BLOB:
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
default: default:
ALOGE("%s badness unsupported format=%x", __FUNCTION__, format); ALOGE("%s badness unsupported HAL format=%x", __FUNCTION__, halFormat);
} }
return GL_RGBA;
return GL_RGBA;
} }
// Used internally GLenum GLPixelTypeFromAndroid(int halFormat)
GLenum getPixelFormatFromAndroid(int format)
{ {
switch(format) switch(halFormat)
{ {
case HAL_PIXEL_FORMAT_RGBA_8888: case HAL_PIXEL_FORMAT_RGBA_8888:
case HAL_PIXEL_FORMAT_RGBX_8888: case HAL_PIXEL_FORMAT_RGBX_8888:
case HAL_PIXEL_FORMAT_RGB_888: case HAL_PIXEL_FORMAT_RGB_888:
case HAL_PIXEL_FORMAT_BGRA_8888: case HAL_PIXEL_FORMAT_BGRA_8888:
return GL_UNSIGNED_BYTE; return GL_UNSIGNED_BYTE;
case HAL_PIXEL_FORMAT_RGB_565: case HAL_PIXEL_FORMAT_RGB_565:
return GL_UNSIGNED_SHORT_5_6_5; return GL_UNSIGNED_SHORT_5_6_5;
case HAL_PIXEL_FORMAT_YV12: case HAL_PIXEL_FORMAT_YV12:
return GL_UNSIGNED_BYTE; return GL_UNSIGNED_BYTE;
case HAL_PIXEL_FORMAT_BLOB: case HAL_PIXEL_FORMAT_BLOB:
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
default: default:
ALOGE("%s badness unsupported format=%x", __FUNCTION__, format); ALOGE("%s badness unsupported HAL format=%x", __FUNCTION__, halFormat);
} }
return GL_UNSIGNED_BYTE;
return GL_UNSIGNED_BYTE;
} }
#ifndef ANDROID_COMMON #ifndef ANDROID_COMMON
#define ANDROID_COMMON #define ANDROID_COMMON
// Used internally #include <GLES/gl.h>
GLenum getColorFormatFromAndroid(int format);
// Used internally GLenum GLPixelFormatFromAndroid(int format);
GLenum getPixelFormatFromAndroid(int format); GLenum GLPixelTypeFromAndroid(int format);
#endif // ANDROID_COMMON #endif // ANDROID_COMMON
...@@ -181,8 +181,8 @@ class AndroidNativeImage : public egl::Image ...@@ -181,8 +181,8 @@ class AndroidNativeImage : public egl::Image
public: public:
explicit AndroidNativeImage(ANativeWindowBuffer *nativeBuffer) explicit AndroidNativeImage(ANativeWindowBuffer *nativeBuffer)
: egl::Image(0, nativeBuffer->width, nativeBuffer->height, 1, : egl::Image(0, nativeBuffer->width, nativeBuffer->height, 1,
getColorFormatFromAndroid(nativeBuffer->format), GLPixelFormatFromAndroid(nativeBuffer->format),
getPixelFormatFromAndroid(nativeBuffer->format)), GLPixelTypeFromAndroid(nativeBuffer->format)),
nativeBuffer(nativeBuffer) nativeBuffer(nativeBuffer)
{ {
nativeBuffer->common.incRef(&nativeBuffer->common); nativeBuffer->common.incRef(&nativeBuffer->common);
...@@ -204,25 +204,30 @@ private: ...@@ -204,25 +204,30 @@ private:
virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client) virtual void *lockInternal(int x, int y, int z, sw::Lock lock, sw::Accessor client)
{ {
LOGLOCK("image=%p op=%s.swsurface lock=%d", this, __FUNCTION__, lock); LOGLOCK("image=%p op=%s.swsurface lock=%d", this, __FUNCTION__, lock);
// Always do this for reference counting. // Always do this for reference counting.
void *data = sw::Surface::lockInternal(x, y, z, lock, client); void *data = sw::Surface::lockInternal(x, y, z, lock, client);
if(nativeBuffer) if(nativeBuffer)
{ {
if (x || y || z) if(x != 0 || y != 0 || z != 0)
{ {
ALOGI("badness: %s called with unsupported parms: image=%p x=%d y=%d z=%d", __FUNCTION__, this, x, y, z); ALOGI("badness: %s called with unsupported parms: image=%p x=%d y=%d z=%d", __FUNCTION__, this, x, y, z);
} }
LOGLOCK("image=%p op=%s.ani lock=%d", this, __FUNCTION__, lock); LOGLOCK("image=%p op=%s.ani lock=%d", this, __FUNCTION__, lock);
// Lock the ANativeWindowBuffer and use its address. // Lock the ANativeWindowBuffer and use its address.
data = lockNativeBuffer( data = lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
if (lock == sw::LOCK_UNLOCKED) if(lock == sw::LOCK_UNLOCKED)
{ {
// We're never going to get a corresponding unlock, so unlock // We're never going to get a corresponding unlock, so unlock
// immediately. This keeps the gralloc reference counts sane. // immediately. This keeps the gralloc reference counts sane.
unlockNativeBuffer(); unlockNativeBuffer();
} }
} }
return data; return data;
} }
...@@ -233,6 +238,7 @@ private: ...@@ -233,6 +238,7 @@ private:
LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__); LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__);
unlockNativeBuffer(); unlockNativeBuffer();
} }
LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__); LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__);
sw::Surface::unlockInternal(); sw::Surface::unlockInternal();
} }
...@@ -241,6 +247,7 @@ private: ...@@ -241,6 +247,7 @@ private:
{ {
LOGLOCK("image=%p op=%s lock=%d", this, __FUNCTION__, lock); LOGLOCK("image=%p op=%s lock=%d", this, __FUNCTION__, lock);
(void)sw::Surface::lockExternal(left, top, 0, lock, sw::PUBLIC); (void)sw::Surface::lockExternal(left, top, 0, lock, sw::PUBLIC);
return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); return lockNativeBuffer(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
} }
...@@ -248,16 +255,16 @@ private: ...@@ -248,16 +255,16 @@ private:
{ {
LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__); LOGLOCK("image=%p op=%s.ani", this, __FUNCTION__);
unlockNativeBuffer(); unlockNativeBuffer();
LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__); LOGLOCK("image=%p op=%s.swsurface", this, __FUNCTION__);
sw::Surface::unlockExternal(); sw::Surface::unlockExternal();
} }
void* lockNativeBuffer(int usage) void* lockNativeBuffer(int usage)
{ {
void *buffer = 0; void *buffer = nullptr;
GrallocModule::getInstance()->lock( GrallocModule::getInstance()->lock(nativeBuffer->handle, usage, 0, 0, nativeBuffer->width, nativeBuffer->height, &buffer);
nativeBuffer->handle, usage, 0, 0,
nativeBuffer->width, nativeBuffer->height, &buffer);
return buffer; return buffer;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment