OSDN Git Service

Android: Introduce ANDROID_HOST_BUILD and rework logging.
authorAlistair Strachan <astrachan@google.com>
Sat, 24 Mar 2018 19:24:00 +0000 (12:24 -0700)
committerAlistair Strachan <astrachan@google.com>
Wed, 29 Aug 2018 16:51:58 +0000 (16:51 +0000)
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/18028
Tested-by: Alistair Strachan <astrachan@google.com>
Reviewed-by: Greg Hartman <ghartman@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
14 files changed:
src/Common/Debug.hpp
src/Common/GrallocAndroid.cpp
src/Common/GrallocAndroid.hpp
src/Main/FrameBuffer.cpp
src/Main/FrameBufferAndroid.cpp
src/OpenGL/common/Image.hpp
src/OpenGL/common/debug.cpp
src/OpenGL/common/debug.h
src/OpenGL/compiler/ConstantUnion.h
src/OpenGL/compiler/SymbolTable.h
src/OpenGL/compiler/debug.h
src/OpenGL/libEGL/Display.cpp
src/OpenGL/libEGL/libEGL.cpp
src/OpenGL/libGLESv2/libGLESv2.cpp

index 5ccc35a..436854c 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef Debug_hpp
 #define Debug_hpp
 
-#ifdef __ANDROID__
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
 #include "DebugAndroid.hpp"
 #else
 
index 4f87368..c877e99 100644 (file)
 // limitations under the License.
 
 #include "GrallocAndroid.hpp"
+#include "Debug.hpp"
 
-#include <cutils/log.h>
+#ifdef HAVE_GRALLOC1
+#include <sync/sync.h>
+#endif
 
 GrallocModule *GrallocModule::getInstance()
 {
@@ -41,7 +44,63 @@ GrallocModule::GrallocModule()
                break;
 #endif
        default:
-               ALOGE("unknown gralloc major version (%d)", m_major_version);
+               TRACE("unknown gralloc major version (%d)", m_major_version);
                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;
+               }
+       }
+}
index 3ebb5d7..fe0b15a 100644 (file)
 #define GRALLOC_ANDROID
 
 #include <hardware/gralloc.h>
-#include <cutils/log.h>
 
 #ifdef HAVE_GRALLOC1
 #include <hardware/gralloc1.h>
-#include <sync/sync.h>
 #endif
 
 #include <unistd.h> // for close()
@@ -29,61 +27,8 @@ class GrallocModule
 {
 public:
        static GrallocModule *getInstance();
-       int 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:
-                       {
-                               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;
-                       }
-               }
-       }
+       int lock(buffer_handle_t handle, int usage, int left, int top, int width, int height, void **vaddr);
+       int unlock(buffer_handle_t handle);
 
 private:
        GrallocModule();
index 82dff46..7a8ddc1 100644 (file)
 #include <string.h>
 #include <time.h>
 
-#ifdef __ANDROID__
-#include <cutils/properties.h>
-#endif
-
 #define ASYNCHRONOUS_BLIT false   // FIXME: Currently leads to rare race conditions
 
 namespace sw
index 9b47171..0ae5f09 100644 (file)
@@ -17,7 +17,6 @@
 #include "Common/GrallocAndroid.hpp"
 
 #include <system/window.h>
-#include <cutils/log.h>
 
 namespace sw
 {
@@ -88,14 +87,14 @@ namespace sw
                                 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
                                 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;
                }
 
                if((buffer->width < width) || (buffer->height < height))
                {
-                       ALOGI("lock failed: buffer of %dx%d too small for window of %dx%d",
-                                 buffer->width, buffer->height, width, height);
+                       TRACE("lock failed: buffer of %dx%d too small for window of %dx%d",
+                             buffer->width, buffer->height, width, height);
                        return nullptr;
                }
 
@@ -110,11 +109,11 @@ namespace sw
                case HAL_PIXEL_FORMAT_BGRA_8888: format = FORMAT_A8R8G8B8; break;
                case HAL_PIXEL_FORMAT_RGB_888:
                        // 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.
                        break;
                default:
-                       ALOGE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
+                       TRACE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
                        format = FORMAT_NULL;
                        break;
                }
@@ -127,7 +126,7 @@ namespace sw
        {
                if(!buffer)
                {
-                       ALOGE("%s: badness unlock with no active buffer", __FUNCTION__);
+                       TRACE("%s: badness unlock with no active buffer", __FUNCTION__);
                        return;
                }
 
@@ -135,7 +134,7 @@ namespace sw
 
                if(GrallocModule::getInstance()->unlock(buffer->handle) != 0)
                {
-                       ALOGE("%s: badness unlock failed", __FUNCTION__);
+                       TRACE("%s: badness unlock failed", __FUNCTION__);
                }
        }
 }
index a744763..f115a63 100644 (file)
 #if defined(__ANDROID__)
 #include <system/window.h>
 #include "../../Common/GrallocAndroid.hpp"
+#endif
+
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
 #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
 #include <assert.h>
 #define LOGLOCK(...)
@@ -255,7 +258,7 @@ inline GLenum GLPixelFormatFromAndroid(int halFormat)
 #endif
        case HAL_PIXEL_FORMAT_RGB_888:   // Unsupported.
        default:
-               ALOGE("Unsupported EGL image format %d", halFormat); ASSERT(false);
+               ERR("Unsupported EGL image format %d", halFormat); ASSERT(false);
                return GL_NONE;
        }
 }
@@ -293,7 +296,7 @@ private:
                {
                        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);
index a7ced89..3ef2885 100644 (file)
@@ -26,8 +26,8 @@
 
 namespace es
 {
-#ifdef __ANDROID__
-       void output(const char *format, va_list vararg)
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
+       static void output(const char *format, va_list vararg)
        {
                ALOGI("%s", android::String8::formatV(format, vararg).string());
        }
index aadb535..a5653b7 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef COMMON_DEBUG_H_
 #define COMMON_DEBUG_H_
 
-#ifdef __ANDROID__
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
 #include "../../Common/DebugAndroid.hpp"
 #else
 #include <stdio.h>
index 6b1050f..89b21e1 100644 (file)
 #ifndef _CONSTANT_UNION_INCLUDED_
 #define _CONSTANT_UNION_INCLUDED_
 
-#ifndef __ANDROID__
-#include <assert.h>
-#else
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
 #include "../../Common/DebugAndroid.hpp"
+#else
+#include <assert.h>
 #endif
 
 class ConstantUnion {
index 3466f2f..2fbf3cf 100644 (file)
 //   are tracked in the intermediate representation, not the symbol table.
 //
 
-#ifndef __ANDROID__
-#include <assert.h>
-#else
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
 #include "../../Common/DebugAndroid.hpp"
+#else
+#include <assert.h>
 #endif
 
 #include "InfoSink.h"
index 2755d23..77798ef 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef COMPILER_DEBUG_H_
 #define COMPILER_DEBUG_H_
 
-#ifdef __ANDROID__
+#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
 #include "../../Common/DebugAndroid.hpp"
 
 #define Trace(...) ((void)0)
index 5821ba9..8bbed9e 100644 (file)
@@ -668,12 +668,12 @@ bool Display::isValidWindow(EGLNativeWindowType window)
        #elif defined(__ANDROID__)
                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;
                }
                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 true;
index b2ef237..a4f078d 100644 (file)
@@ -1172,7 +1172,7 @@ EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBu
 
                        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);
                        }
 
index b3f1d20..1577569 100644 (file)
 #include <algorithm>
 #include <limits>
 
-#ifdef __ANDROID__
-#include <cutils/log.h>
-#endif
-
 namespace es2
 {
 
@@ -2807,11 +2803,7 @@ void GetIntegerv(GLenum pname, GLint* params)
        if(!context)
        {
                // Not strictly an error, but probably unintended or attempting to rely on non-compliant behavior
-               #ifdef __ANDROID__
-                       ALOGI("expected_badness glGetIntegerv() called without current context.");
-               #else
-                       ERR("glGetIntegerv() called without current context.");
-               #endif
+               ERR("glGetIntegerv() called without current context.");
 
                // 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,