Commit c28d28a5 by Alistair Strachan

Android: Introduce ANDROID_HOST_BUILD and rework logging.

Avoid using the Android logger directly. Instead, use the Common/Debug and OpenGL/common/debug paths instead, which abstracts away use of the logger. Add ANDRIOD_HOST_BUILD to tell the build we are building an Android swiftshader, but minimizing the use of platform features such as the logger. Change-Id: Ic6c70843d947c568d0e29fe66c55af74b8559a59 Reviewed-on: https://swiftshader-review.googlesource.com/18028Tested-by: 's avatarAlistair Strachan <astrachan@google.com> Reviewed-by: 's avatarGreg Hartman <ghartman@google.com> Reviewed-by: 's avatarLingfeng Yang <lfy@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 94d4660d
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef Debug_hpp #ifndef Debug_hpp
#define Debug_hpp #define Debug_hpp
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
#include "DebugAndroid.hpp" #include "DebugAndroid.hpp"
#else #else
......
...@@ -13,8 +13,11 @@ ...@@ -13,8 +13,11 @@
// limitations under the License. // limitations under the License.
#include "GrallocAndroid.hpp" #include "GrallocAndroid.hpp"
#include "Debug.hpp"
#include <cutils/log.h> #ifdef HAVE_GRALLOC1
#include <sync/sync.h>
#endif
GrallocModule *GrallocModule::getInstance() GrallocModule *GrallocModule::getInstance()
{ {
...@@ -41,7 +44,63 @@ GrallocModule::GrallocModule() ...@@ -41,7 +44,63 @@ GrallocModule::GrallocModule()
break; break;
#endif #endif
default: default:
ALOGE("unknown gralloc major version (%d)", m_major_version); TRACE("unknown gralloc major version (%d)", m_major_version);
break; break;
} }
} }
int GrallocModule::lock(buffer_handle_t handle, int usage, int left, int top, int width, int height, void **vaddr)
{
switch(m_major_version)
{
case 0:
{
return m_module->lock(m_module, handle, usage, left, top, width, height, vaddr);
}
case 1:
#ifdef HAVE_GRALLOC1
{
gralloc1_rect_t outRect{};
outRect.left = left;
outRect.top = top;
outRect.width = width;
outRect.height = height;
return m_gralloc1_lock(m_gralloc1_device, handle, usage, usage, &outRect, vaddr, -1);
}
#endif
default:
{
TRACE("no gralloc module to lock");
return -1;
}
}
}
int GrallocModule::unlock(buffer_handle_t handle)
{
switch(m_major_version)
{
case 0:
{
return m_module->unlock(m_module, handle);
}
case 1:
#ifdef HAVE_GRALLOC1
{
int32_t fenceFd = -1;
int error = m_gralloc1_unlock(m_gralloc1_device, handle, &fenceFd);
if (!error)
{
sync_wait(fenceFd, -1);
close(fenceFd);
}
return error;
}
#endif
default:
{
TRACE("no gralloc module to unlock");
return -1;
}
}
}
...@@ -16,11 +16,9 @@ ...@@ -16,11 +16,9 @@
#define GRALLOC_ANDROID #define GRALLOC_ANDROID
#include <hardware/gralloc.h> #include <hardware/gralloc.h>
#include <cutils/log.h>
#ifdef HAVE_GRALLOC1 #ifdef HAVE_GRALLOC1
#include <hardware/gralloc1.h> #include <hardware/gralloc1.h>
#include <sync/sync.h>
#endif #endif
#include <unistd.h> // for close() #include <unistd.h> // for close()
...@@ -29,61 +27,8 @@ class GrallocModule ...@@ -29,61 +27,8 @@ class GrallocModule
{ {
public: public:
static GrallocModule *getInstance(); static GrallocModule *getInstance();
int lock(buffer_handle_t handle, int usage, int left, int top, int width, int height, void **vaddr) int lock(buffer_handle_t handle, int usage, int left, int top, int width, int height, void **vaddr);
{ int unlock(buffer_handle_t handle);
switch(m_major_version)
{
case 0:
{
return m_module->lock(m_module, handle, usage, left, top, width, height, vaddr);
}
case 1:
#ifdef HAVE_GRALLOC1
{
gralloc1_rect_t outRect{};
outRect.left = left;
outRect.top = top;
outRect.width = width;
outRect.height = height;
return m_gralloc1_lock(m_gralloc1_device, handle, usage, usage, &outRect, vaddr, -1);
}
#endif
default:
{
ALOGE("no gralloc module to lock");
return -1;
}
}
}
int unlock(buffer_handle_t handle)
{
switch(m_major_version)
{
case 0:
{
return m_module->unlock(m_module, handle);
}
case 1:
#ifdef HAVE_GRALLOC1
{
int32_t fenceFd = -1;
int error = m_gralloc1_unlock(m_gralloc1_device, handle, &fenceFd);
if (!error)
{
sync_wait(fenceFd, -1);
close(fenceFd);
}
return error;
}
#endif
default:
{
ALOGE("no gralloc module to unlock");
return -1;
}
}
}
private: private:
GrallocModule(); GrallocModule();
......
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#ifdef __ANDROID__
#include <cutils/properties.h>
#endif
#define ASYNCHRONOUS_BLIT false // FIXME: Currently leads to rare race conditions #define ASYNCHRONOUS_BLIT false // FIXME: Currently leads to rare race conditions
namespace sw namespace sw
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "Common/GrallocAndroid.hpp" #include "Common/GrallocAndroid.hpp"
#include <system/window.h> #include <system/window.h>
#include <cutils/log.h>
namespace sw namespace sw
{ {
...@@ -88,14 +87,14 @@ namespace sw ...@@ -88,14 +87,14 @@ namespace sw
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
0, 0, buffer->width, buffer->height, &framebuffer) != 0) 0, 0, buffer->width, buffer->height, &framebuffer) != 0)
{ {
ALOGE("%s failed to lock buffer %p", __FUNCTION__, buffer); TRACE("%s failed to lock buffer %p", __FUNCTION__, buffer);
return nullptr; return nullptr;
} }
if((buffer->width < width) || (buffer->height < height)) if((buffer->width < width) || (buffer->height < height))
{ {
ALOGI("lock failed: buffer of %dx%d too small for window of %dx%d", TRACE("lock failed: buffer of %dx%d too small for window of %dx%d",
buffer->width, buffer->height, width, height); buffer->width, buffer->height, width, height);
return nullptr; return nullptr;
} }
...@@ -110,11 +109,11 @@ namespace sw ...@@ -110,11 +109,11 @@ namespace sw
case HAL_PIXEL_FORMAT_BGRA_8888: format = FORMAT_A8R8G8B8; break; case HAL_PIXEL_FORMAT_BGRA_8888: format = FORMAT_A8R8G8B8; break;
case HAL_PIXEL_FORMAT_RGB_888: case HAL_PIXEL_FORMAT_RGB_888:
// Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit. // Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit.
ALOGE("Unsupported frame buffer format RGB_888"); ASSERT(false); TRACE("Unsupported frame buffer format RGB_888"); ASSERT(false);
format = FORMAT_R8G8B8; // Wrong component order. format = FORMAT_R8G8B8; // Wrong component order.
break; break;
default: default:
ALOGE("Unsupported frame buffer format %d", buffer->format); ASSERT(false); TRACE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
format = FORMAT_NULL; format = FORMAT_NULL;
break; break;
} }
...@@ -127,7 +126,7 @@ namespace sw ...@@ -127,7 +126,7 @@ namespace sw
{ {
if(!buffer) if(!buffer)
{ {
ALOGE("%s: badness unlock with no active buffer", __FUNCTION__); TRACE("%s: badness unlock with no active buffer", __FUNCTION__);
return; return;
} }
...@@ -135,7 +134,7 @@ namespace sw ...@@ -135,7 +134,7 @@ namespace sw
if(GrallocModule::getInstance()->unlock(buffer->handle) != 0) if(GrallocModule::getInstance()->unlock(buffer->handle) != 0)
{ {
ALOGE("%s: badness unlock failed", __FUNCTION__); TRACE("%s: badness unlock failed", __FUNCTION__);
} }
} }
} }
......
...@@ -24,8 +24,11 @@ ...@@ -24,8 +24,11 @@
#if defined(__ANDROID__) #if defined(__ANDROID__)
#include <system/window.h> #include <system/window.h>
#include "../../Common/GrallocAndroid.hpp" #include "../../Common/GrallocAndroid.hpp"
#endif
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#define LOGLOCK(fmt, ...) // ALOGI(fmt " tid=%d", ##__VA_ARGS__, gettid()) #define LOGLOCK(fmt, ...) // TRACE(fmt " tid=%d", ##__VA_ARGS__, gettid())
#else #else
#include <assert.h> #include <assert.h>
#define LOGLOCK(...) #define LOGLOCK(...)
...@@ -255,7 +258,7 @@ inline GLenum GLPixelFormatFromAndroid(int halFormat) ...@@ -255,7 +258,7 @@ inline GLenum GLPixelFormatFromAndroid(int halFormat)
#endif #endif
case HAL_PIXEL_FORMAT_RGB_888: // Unsupported. case HAL_PIXEL_FORMAT_RGB_888: // Unsupported.
default: default:
ALOGE("Unsupported EGL image format %d", halFormat); ASSERT(false); ERR("Unsupported EGL image format %d", halFormat); ASSERT(false);
return GL_NONE; return GL_NONE;
} }
} }
...@@ -293,7 +296,7 @@ private: ...@@ -293,7 +296,7 @@ private:
{ {
if(x != 0 || y != 0 || z != 0) 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); TRACE("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);
......
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
namespace es namespace es
{ {
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
void output(const char *format, va_list vararg) static void output(const char *format, va_list vararg)
{ {
ALOGI("%s", android::String8::formatV(format, vararg).string()); ALOGI("%s", android::String8::formatV(format, vararg).string());
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#ifndef COMMON_DEBUG_H_ #ifndef COMMON_DEBUG_H_
#define COMMON_DEBUG_H_ #define COMMON_DEBUG_H_
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#else #else
#include <stdio.h> #include <stdio.h>
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
#ifndef _CONSTANT_UNION_INCLUDED_ #ifndef _CONSTANT_UNION_INCLUDED_
#define _CONSTANT_UNION_INCLUDED_ #define _CONSTANT_UNION_INCLUDED_
#ifndef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
#include <assert.h>
#else
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#else
#include <assert.h>
#endif #endif
class ConstantUnion { class ConstantUnion {
......
...@@ -38,10 +38,10 @@ ...@@ -38,10 +38,10 @@
// are tracked in the intermediate representation, not the symbol table. // are tracked in the intermediate representation, not the symbol table.
// //
#ifndef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
#include <assert.h>
#else
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#else
#include <assert.h>
#endif #endif
#include "InfoSink.h" #include "InfoSink.h"
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#ifndef COMPILER_DEBUG_H_ #ifndef COMPILER_DEBUG_H_
#define COMPILER_DEBUG_H_ #define COMPILER_DEBUG_H_
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#define Trace(...) ((void)0) #define Trace(...) ((void)0)
......
...@@ -668,12 +668,12 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -668,12 +668,12 @@ bool Display::isValidWindow(EGLNativeWindowType window)
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
if(!window) if(!window)
{ {
ALOGE("%s called with window==NULL %s:%d", __FUNCTION__, __FILE__, __LINE__); ERR("%s called with window==NULL %s:%d", __FUNCTION__, __FILE__, __LINE__);
return false; return false;
} }
if(static_cast<ANativeWindow*>(window)->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) if(static_cast<ANativeWindow*>(window)->common.magic != ANDROID_NATIVE_WINDOW_MAGIC)
{ {
ALOGE("%s called with window==%p bad magic %s:%d", __FUNCTION__, window, __FILE__, __LINE__); ERR("%s called with window==%p bad magic %s:%d", __FUNCTION__, window, __FILE__, __LINE__);
return false; return false;
} }
return true; return true;
......
...@@ -1172,7 +1172,7 @@ EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBu ...@@ -1172,7 +1172,7 @@ EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBu
if(!nativeBuffer || GLPixelFormatFromAndroid(nativeBuffer->format) == GL_NONE) if(!nativeBuffer || GLPixelFormatFromAndroid(nativeBuffer->format) == GL_NONE)
{ {
ALOGW("%s badness unsupported HAL format=%x", __FUNCTION__, nativeBuffer ? nativeBuffer->format : 0); ERR("%s badness unsupported HAL format=%x", __FUNCTION__, nativeBuffer ? nativeBuffer->format : 0);
return error(EGL_BAD_ATTRIBUTE, EGL_NO_IMAGE_KHR); return error(EGL_BAD_ATTRIBUTE, EGL_NO_IMAGE_KHR);
} }
......
...@@ -37,10 +37,6 @@ ...@@ -37,10 +37,6 @@
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
#ifdef __ANDROID__
#include <cutils/log.h>
#endif
namespace es2 namespace es2
{ {
...@@ -2807,11 +2803,7 @@ void GetIntegerv(GLenum pname, GLint* params) ...@@ -2807,11 +2803,7 @@ void GetIntegerv(GLenum pname, GLint* params)
if(!context) if(!context)
{ {
// Not strictly an error, but probably unintended or attempting to rely on non-compliant behavior // Not strictly an error, but probably unintended or attempting to rely on non-compliant behavior
#ifdef __ANDROID__ ERR("glGetIntegerv() called without current context.");
ALOGI("expected_badness glGetIntegerv() called without current context.");
#else
ERR("glGetIntegerv() called without current context.");
#endif
// This is not spec compliant! When there is no current GL context, functions should // This is not spec compliant! When there is no current GL context, functions should
// have no side effects. Google Maps queries these values before creating a context, // have no side effects. Google Maps queries these values before creating a context,
......
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