diff options
Diffstat (limited to 'minui')
-rw-r--r-- | minui/Android.bp | 46 | ||||
-rw-r--r-- | minui/Android.mk | 85 | ||||
-rw-r--r-- | minui/graphics.cpp | 96 | ||||
-rw-r--r-- | minui/graphics_adf.cpp | 19 | ||||
-rw-r--r-- | minui/graphics_drm.cpp | 19 | ||||
-rw-r--r-- | minui/include/minui/minui.h | 20 | ||||
-rw-r--r-- | minui/resources.cpp | 20 |
7 files changed, 160 insertions, 145 deletions
diff --git a/minui/Android.bp b/minui/Android.bp new file mode 100644 index 000000000..19d28be62 --- /dev/null +++ b/minui/Android.bp @@ -0,0 +1,46 @@ +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_library { + name: "libminui", + + defaults: [ + "recovery_defaults", + ], + + export_include_dirs: [ + "include", + ], + + srcs: [ + "events.cpp", + "graphics.cpp", + "graphics_adf.cpp", + "graphics_drm.cpp", + "graphics_fbdev.cpp", + "resources.cpp", + ], + + whole_static_libs: [ + "libadf", + "libdrm", + "libsync_recovery", + ], + + shared_libs: [ + "libbase", + "libpng", + "libz", + ], +} diff --git a/minui/Android.mk b/minui/Android.mk deleted file mode 100644 index ae1552b1b..000000000 --- a/minui/Android.mk +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (C) 2007 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -LOCAL_PATH := $(call my-dir) - -# libminui (static library) -# =============================== -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := \ - events.cpp \ - graphics.cpp \ - graphics_adf.cpp \ - graphics_drm.cpp \ - graphics_fbdev.cpp \ - resources.cpp \ - -LOCAL_WHOLE_STATIC_LIBRARIES := \ - libadf \ - libdrm \ - libsync_recovery - -LOCAL_STATIC_LIBRARIES := \ - libpng \ - libbase - -LOCAL_CFLAGS := -Wall -Werror -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include - -LOCAL_MODULE := libminui - -# This used to compare against values in double-quotes (which are just -# ordinary characters in this context). Strip double-quotes from the -# value so that either will work. - -ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),ABGR_8888) - LOCAL_CFLAGS += -DRECOVERY_ABGR -endif -ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),RGBX_8888) - LOCAL_CFLAGS += -DRECOVERY_RGBX -endif -ifeq ($(subst ",,$(TARGET_RECOVERY_PIXEL_FORMAT)),BGRA_8888) - LOCAL_CFLAGS += -DRECOVERY_BGRA -endif - -ifneq ($(TARGET_RECOVERY_OVERSCAN_PERCENT),) - LOCAL_CFLAGS += -DOVERSCAN_PERCENT=$(TARGET_RECOVERY_OVERSCAN_PERCENT) -else - LOCAL_CFLAGS += -DOVERSCAN_PERCENT=0 -endif - -ifneq ($(TARGET_RECOVERY_DEFAULT_ROTATION),) - LOCAL_CFLAGS += -DDEFAULT_ROTATION=$(TARGET_RECOVERY_DEFAULT_ROTATION) -else - LOCAL_CFLAGS += -DDEFAULT_ROTATION=ROTATION_NONE -endif - -include $(BUILD_STATIC_LIBRARY) - -# libminui (shared library) -# =============================== -# Used by OEMs for factory test images. -include $(CLEAR_VARS) -LOCAL_MODULE := libminui -LOCAL_WHOLE_STATIC_LIBRARIES += libminui -LOCAL_SHARED_LIBRARIES := \ - libpng \ - libbase - -LOCAL_CFLAGS := -Wall -Werror -LOCAL_C_INCLUDES := $(LOCAL_PATH)/include -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include -include $(BUILD_SHARED_LIBRARY) diff --git a/minui/graphics.cpp b/minui/graphics.cpp index cc02e9e82..4fe0fdc7b 100644 --- a/minui/graphics.cpp +++ b/minui/graphics.cpp @@ -23,6 +23,8 @@ #include <memory> +#include <android-base/properties.h> + #include "graphics_adf.h" #include "graphics_drm.h" #include "graphics_fbdev.h" @@ -31,7 +33,6 @@ static GRFont* gr_font = nullptr; static MinuiBackend* gr_backend = nullptr; -static int overscan_percent = OVERSCAN_PERCENT; static int overscan_offset_x = 0; static int overscan_offset_y = 0; @@ -40,17 +41,23 @@ static constexpr uint32_t alpha_mask = 0xff000000; // gr_draw is owned by backends. static const GRSurface* gr_draw = nullptr; -static GRRotation rotation = ROTATION_NONE; +static GRRotation rotation = GRRotation::NONE; +static PixelFormat pixel_format = PixelFormat::UNKNOWN; static bool outside(int x, int y) { - return x < 0 || x >= (rotation % 2 ? gr_draw->height : gr_draw->width) || y < 0 || - y >= (rotation % 2 ? gr_draw->width : gr_draw->height); + auto swapped = (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT); + return x < 0 || x >= (swapped ? gr_draw->height : gr_draw->width) || y < 0 || + y >= (swapped ? gr_draw->width : gr_draw->height); } const GRFont* gr_sys_font() { return gr_font; } +PixelFormat gr_pixel_format() { + return pixel_format; +} + int gr_measure(const GRFont* font, const char* s) { if (font == nullptr) { return -1; @@ -89,36 +96,44 @@ static inline uint32_t pixel_blend(uint8_t alpha, uint32_t pix) { // Increments pixel pointer right, with current rotation. static void incr_x(uint32_t** p, int row_pixels) { - if (rotation % 2) { - *p = *p + (rotation == 1 ? 1 : -1) * row_pixels; - } else { - *p = *p + (rotation ? -1 : 1); + if (rotation == GRRotation::LEFT) { + *p = *p - row_pixels; + } else if (rotation == GRRotation::RIGHT) { + *p = *p + row_pixels; + } else if (rotation == GRRotation::DOWN) { + *p = *p - 1; + } else { // GRRotation::NONE + *p = *p + 1; } } // Increments pixel pointer down, with current rotation. static void incr_y(uint32_t** p, int row_pixels) { - if (rotation % 2) { - *p = *p + (rotation == 1 ? -1 : 1); - } else { - *p = *p + (rotation ? -1 : 1) * row_pixels; + if (rotation == GRRotation::LEFT) { + *p = *p + 1; + } else if (rotation == GRRotation::RIGHT) { + *p = *p - 1; + } else if (rotation == GRRotation::DOWN) { + *p = *p - row_pixels; + } else { // GRRotation::NONE + *p = *p + row_pixels; } } // Returns pixel pointer at given coordinates with rotation adjustment. static uint32_t* pixel_at(const GRSurface* surf, int x, int y, int row_pixels) { switch (rotation) { - case ROTATION_NONE: + case GRRotation::NONE: return reinterpret_cast<uint32_t*>(surf->data) + y * row_pixels + x; - case ROTATION_RIGHT: + case GRRotation::RIGHT: return reinterpret_cast<uint32_t*>(surf->data) + x * row_pixels + (surf->width - y); - case ROTATION_DOWN: + case GRRotation::DOWN: return reinterpret_cast<uint32_t*>(surf->data) + (surf->height - 1 - y) * row_pixels + (surf->width - 1 - x); - case ROTATION_LEFT: + case GRRotation::LEFT: return reinterpret_cast<uint32_t*>(surf->data) + (surf->height - 1 - x) * row_pixels + y; default: - printf("invalid rotation %d", rotation); + printf("invalid rotation %d", static_cast<int>(rotation)); } return nullptr; } @@ -194,11 +209,11 @@ void gr_texticon(int x, int y, GRSurface* icon) { void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { uint32_t r32 = r, g32 = g, b32 = b, a32 = a; -#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA) - gr_current = (a32 << 24) | (r32 << 16) | (g32 << 8) | b32; -#else - gr_current = (a32 << 24) | (b32 << 16) | (g32 << 8) | r32; -#endif + if (pixel_format == PixelFormat::ABGR || pixel_format == PixelFormat::BGRA) { + gr_current = (a32 << 24) | (r32 << 16) | (g32 << 8) | b32; + } else { + gr_current = (a32 << 24) | (b32 << 16) | (g32 << 8) | r32; + } } void gr_clear() { @@ -256,7 +271,7 @@ void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) { if (outside(dx, dy) || outside(dx + w - 1, dy + h - 1)) return; - if (rotation) { + if (rotation != GRRotation::NONE) { int src_row_pixels = source->row_bytes / source->pixel_bytes; int row_pixels = gr_draw->row_bytes / gr_draw->pixel_bytes; uint32_t* src_py = reinterpret_cast<uint32_t*>(source->data) + sy * source->row_bytes / 4 + sx; @@ -326,6 +341,18 @@ void gr_flip() { } int gr_init() { + // pixel_format needs to be set before loading any resources or initializing backends. + std::string format = android::base::GetProperty("ro.recovery.ui.pixel_format", ""); + if (format == "ABGR_8888") { + pixel_format = PixelFormat::ABGR; + } else if (format == "RGBX_8888") { + pixel_format = PixelFormat::RGBX; + } else if (format == "BGRA_8888") { + pixel_format = PixelFormat::BGRA; + } else { + pixel_format = PixelFormat::UNKNOWN; + } + int ret = gr_init_font("font", &gr_font); if (ret != 0) { printf("Failed to init font: %d, continuing graphic backend initialization without font file\n", @@ -351,6 +378,7 @@ int gr_init() { gr_backend = backend.release(); + int overscan_percent = android::base::GetIntProperty("ro.recovery.ui.overscan_percent", 0); overscan_offset_x = gr_draw->width * overscan_percent / 100; overscan_offset_y = gr_draw->height * overscan_percent / 100; @@ -361,7 +389,17 @@ int gr_init() { return -1; } - gr_rotate(DEFAULT_ROTATION); + std::string rotation_str = + android::base::GetProperty("ro.recovery.ui.default_rotation", "ROTATION_NONE"); + if (rotation_str == "ROTATION_RIGHT") { + gr_rotate(GRRotation::RIGHT); + } else if (rotation_str == "ROTATION_DOWN") { + gr_rotate(GRRotation::DOWN); + } else if (rotation_str == "ROTATION_LEFT") { + gr_rotate(GRRotation::LEFT); + } else { // "ROTATION_NONE" or unknown string + gr_rotate(GRRotation::NONE); + } if (gr_draw->pixel_bytes != 4) { printf("gr_init: Only 4-byte pixel formats supported\n"); @@ -379,13 +417,15 @@ void gr_exit() { } int gr_fb_width() { - return rotation % 2 ? gr_draw->height - 2 * overscan_offset_y - : gr_draw->width - 2 * overscan_offset_x; + return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT) + ? gr_draw->height - 2 * overscan_offset_y + : gr_draw->width - 2 * overscan_offset_x; } int gr_fb_height() { - return rotation % 2 ? gr_draw->width - 2 * overscan_offset_x - : gr_draw->height - 2 * overscan_offset_y; + return (rotation == GRRotation::LEFT || rotation == GRRotation::RIGHT) + ? gr_draw->width - 2 * overscan_offset_x + : gr_draw->height - 2 * overscan_offset_y; } void gr_fb_blank(bool blank) { diff --git a/minui/graphics_adf.cpp b/minui/graphics_adf.cpp index a59df00c6..7439df9ac 100644 --- a/minui/graphics_adf.cpp +++ b/minui/graphics_adf.cpp @@ -104,15 +104,16 @@ int MinuiBackendAdf::DeviceInit(adf_device* dev) { } GRSurface* MinuiBackendAdf::Init() { -#if defined(RECOVERY_ABGR) - format = DRM_FORMAT_ABGR8888; -#elif defined(RECOVERY_BGRA) - format = DRM_FORMAT_BGRA8888; -#elif defined(RECOVERY_RGBX) - format = DRM_FORMAT_RGBX8888; -#else - format = DRM_FORMAT_RGB565; -#endif + PixelFormat pixel_format = gr_pixel_format(); + if (pixel_format == PixelFormat::ABGR) { + format = DRM_FORMAT_ABGR8888; + } else if (pixel_format == PixelFormat::BGRA) { + format = DRM_FORMAT_BGRA8888; + } else if (pixel_format == PixelFormat::RGBX) { + format = DRM_FORMAT_RGBX8888; + } else { + format = DRM_FORMAT_RGB565; + } adf_id_t* dev_ids = nullptr; ssize_t n_dev_ids = adf_devices(&dev_ids); diff --git a/minui/graphics_drm.cpp b/minui/graphics_drm.cpp index 57912d1e8..9336a1e63 100644 --- a/minui/graphics_drm.cpp +++ b/minui/graphics_drm.cpp @@ -116,15 +116,16 @@ GRSurfaceDrm* MinuiBackendDrm::DrmCreateSurface(int width, int height) { *surface = {}; uint32_t format; -#if defined(RECOVERY_ABGR) - format = DRM_FORMAT_RGBA8888; -#elif defined(RECOVERY_BGRA) - format = DRM_FORMAT_ARGB8888; -#elif defined(RECOVERY_RGBX) - format = DRM_FORMAT_XBGR8888; -#else - format = DRM_FORMAT_RGB565; -#endif + PixelFormat pixel_format = gr_pixel_format(); + if (pixel_format == PixelFormat::ABGR) { + format = DRM_FORMAT_ABGR8888; + } else if (pixel_format == PixelFormat::BGRA) { + format = DRM_FORMAT_BGRA8888; + } else if (pixel_format == PixelFormat::RGBX) { + format = DRM_FORMAT_RGBX8888; + } else { + format = DRM_FORMAT_RGB565; + } drm_mode_create_dumb create_dumb = {}; create_dumb.height = height; diff --git a/minui/include/minui/minui.h b/minui/include/minui/minui.h index ef4abe252..fa13ecdff 100644 --- a/minui/include/minui/minui.h +++ b/minui/include/minui/minui.h @@ -41,11 +41,18 @@ struct GRFont { int char_height; }; -enum GRRotation { - ROTATION_NONE = 0, - ROTATION_RIGHT = 1, - ROTATION_DOWN = 2, - ROTATION_LEFT = 3, +enum class GRRotation : int { + NONE = 0, + RIGHT = 1, + DOWN = 2, + LEFT = 3, +}; + +enum class PixelFormat : int { + UNKNOWN = 0, + ABGR = 1, + RGBX = 2, + BGRA = 3, }; // Initializes the graphics backend and loads font file. Returns 0 on success, or -1 on error. Note @@ -85,6 +92,9 @@ unsigned int gr_get_height(const GRSurface* surface); // Sets rotation, flips gr_fb_width/height if 90 degree rotation difference void gr_rotate(GRRotation rotation); +// Returns the current PixelFormat being used. +PixelFormat gr_pixel_format(); + // // Input events. // diff --git a/minui/resources.cpp b/minui/resources.cpp index c018d9b8c..477fbe2a2 100644 --- a/minui/resources.cpp +++ b/minui/resources.cpp @@ -207,9 +207,10 @@ int res_create_display_surface(const char* name, GRSurface** pSurface) { return -8; } -#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA) - png_set_bgr(png_ptr); -#endif + PixelFormat pixel_format = gr_pixel_format(); + if (pixel_format == PixelFormat::ABGR || pixel_format == PixelFormat::BGRA) { + png_set_bgr(png_ptr); + } for (png_uint_32 y = 0; y < height; ++y) { std::vector<unsigned char> p_row(width * 4); @@ -278,9 +279,9 @@ int res_create_multi_display_surface(const char* name, int* frames, int* fps, } } -#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA) - png_set_bgr(png_ptr); -#endif + if (gr_pixel_format() == PixelFormat::ABGR || gr_pixel_format() == PixelFormat::BGRA) { + png_set_bgr(png_ptr); + } for (png_uint_32 y = 0; y < height; ++y) { std::vector<unsigned char> p_row(width * 4); @@ -327,9 +328,10 @@ int res_create_alpha_surface(const char* name, GRSurface** pSurface) { surface->row_bytes = width; surface->pixel_bytes = 1; -#if defined(RECOVERY_ABGR) || defined(RECOVERY_BGRA) - png_set_bgr(png_ptr); -#endif + PixelFormat pixel_format = gr_pixel_format(); + if (pixel_format == PixelFormat::ABGR || pixel_format == PixelFormat::BGRA) { + png_set_bgr(png_ptr); + } for (png_uint_32 y = 0; y < height; ++y) { unsigned char* p_row = surface->data + y * surface->row_bytes; |