libtwrpgui: convert gui to use new ziparchive library
Change-Id: Iea94855257c6d02c2f663c25d390cb1cfb91a727
diff --git a/minuitwrp/Android.bp b/minuitwrp/Android.bp
old mode 100755
new mode 100644
index 294b747..ad66477
--- a/minuitwrp/Android.bp
+++ b/minuitwrp/Android.bp
@@ -1,52 +1,58 @@
-bootstrap_go_package {
- name: "soong-libminuitwrp_defaults",
- pkgPath: "bootable/recovery/minuitwrp",
- deps: [
- "soong",
- "soong-android",
- "soong-cc"
- ],
- srcs: [
- "libminuitwrp_defaults.go"
- ],
- pluginFor: ["soong_build"]
-}
-
-libminuitwrp_defaults {
- name: "libminuitwrp_defaults"
-}
-
-cc_library_shared {
- name: "libminuitwrp",
- defaults: ["libminuitwrp_defaults"],
- cflags: [],
- include_dirs: [
- "external/libpng",
- "external/zlib",
- "system/core/include",
- "external/freetype/include",
- "external/libcxx/include",
- "bootable/recovery/twrpinstall/include",
- "bootable/recovery/libpixelflinger/include"
- ],
- srcs: [
- "graphics.cpp",
- "graphics_fbdev.cpp",
- "resources.cpp",
- "truetype.cpp",
- "graphics_utils.cpp",
- "events.cpp"
- ],
- shared_libs: [
- "libft2",
- "libz",
- "libc",
- "libcutils",
- "libpng",
- "libutils",
- "libc++",
- "libcutils",
- "liblog",
- ],
- static_libs: ["libpixelflinger_twrp"]
-}
+bootstrap_go_package {
+ name: "soong-libminuitwrp_defaults",
+ pkgPath: "bootable/recovery/minuitwrp",
+ deps: [
+ "soong",
+ "soong-android",
+ "soong-cc"
+ ],
+ srcs: [
+ "libminuitwrp_defaults.go"
+ ],
+ pluginFor: ["soong_build"]
+}
+
+libminuitwrp_defaults {
+ name: "libminuitwrp_defaults"
+}
+
+cc_library_shared {
+ name: "libminuitwrp",
+ defaults: ["libminuitwrp_defaults"],
+ cflags: [
+ "-DTWRES=\"/twres/\""
+ ],
+ include_dirs: [
+ "external/libpng",
+ "external/zlib",
+ "system/core/include",
+ "external/freetype/include",
+ "external/libcxx/include",
+ "bootable/recovery/twrpinstall/include",
+ "bootable/recovery/libpixelflinger/include",
+ "bootable/recovery/minuitwrp/include",
+ "bootable/recovery/gui/include"
+ ],
+ srcs: [
+ "graphics.cpp",
+ "graphics_fbdev.cpp",
+ "resources.cpp",
+ "truetype.cpp",
+ "graphics_utils.cpp",
+ "events.cpp"
+ ],
+ shared_libs: [
+ "libft2",
+ "libz",
+ "libc",
+ "libcutils",
+ "libpng",
+ "libutils",
+ "libc++",
+ "libcutils",
+ "liblog",
+ "libbase",
+ "libsync"
+ ],
+ static_libs: ["libpixelflinger_twrp"]
+}
diff --git a/minuitwrp/events.cpp b/minuitwrp/events.cpp
old mode 100755
new mode 100644
index 6d576c6..34c01e3
--- a/minuitwrp/events.cpp
+++ b/minuitwrp/events.cpp
@@ -34,7 +34,7 @@
#include "common.h"
-#include "minui.h"
+#include "minuitwrp/minui.h"
//#define _EVENT_LOGGING
diff --git a/minuitwrp/graphics.cpp b/minuitwrp/graphics.cpp
old mode 100755
new mode 100644
index e173437..2c2031a
--- a/minuitwrp/graphics.cpp
+++ b/minuitwrp/graphics.cpp
@@ -33,12 +33,12 @@
#include <cutils/properties.h>
#include <pixelflinger/pixelflinger.h>
-#include "../gui/placement.h"
-#include "minui.h"
+#include "gui/placement.h"
+#include "minuitwrp/minui.h"
#include "graphics.h"
// For std::min and std::max
#include <algorithm>
-#include "truetype.hpp"
+#include "minuitwrp/truetype.hpp"
struct GRFont {
GRSurface* texture;
@@ -260,7 +260,6 @@
r_disp = std::max(x0_disp, x1_disp);
t_disp = std::min(y0_disp, y1_disp);
b_disp = std::max(y0_disp, y1_disp);
-
gl->recti(gl, l_disp, t_disp, r_disp, b_disp);
if(gr_is_curr_clr_opaque)
diff --git a/minuitwrp/graphics.h b/minuitwrp/graphics.h
index a4115fd..5df39ab 100644
--- a/minuitwrp/graphics.h
+++ b/minuitwrp/graphics.h
@@ -17,7 +17,7 @@
#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_
-#include "minui.h"
+#include "minuitwrp/minui.h"
// TODO: lose the function pointers.
struct minui_backend {
diff --git a/minuitwrp/graphics_drm.cpp b/minuitwrp/graphics_drm.cpp
index 409a123..2b94dda 100644
--- a/minuitwrp/graphics_drm.cpp
+++ b/minuitwrp/graphics_drm.cpp
@@ -28,7 +28,7 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
-#include "minui.h"
+#include "minuitwrp/minui.h"
#include "graphics.h"
#include <pixelflinger/pixelflinger.h>
diff --git a/minuitwrp/graphics_drm.h b/minuitwrp/graphics_drm.h
new file mode 100644
index 0000000..2a16af8
--- /dev/null
+++ b/minuitwrp/graphics_drm.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <memory>
+
+#include <xf86drmMode.h>
+
+#include "graphics.h"
+#include "minuitwrp/minui.h"
+
+class GRSurfaceDrm : public GRSurface {
+ public:
+ ~GRSurfaceDrm() override;
+
+ // Creates a GRSurfaceDrm instance.
+ static std::unique_ptr<GRSurfaceDrm> Create(int drm_fd, int width, int height);
+
+ uint8_t* data() override {
+ return mmapped_buffer_;
+ }
+
+ private:
+ friend class MinuiBackendDrm;
+
+ GRSurfaceDrm(size_t width, size_t height, size_t row_bytes, size_t pixel_bytes, int drm_fd,
+ uint32_t handle)
+ : GRSurface(width, height, row_bytes, pixel_bytes), drm_fd_(drm_fd), handle(handle) {}
+
+ const int drm_fd_;
+
+ uint32_t fb_id{ 0 };
+ uint32_t handle{ 0 };
+ uint8_t* mmapped_buffer_{ nullptr };
+};
+
+class MinuiBackendDrm : public MinuiBackend {
+ public:
+ MinuiBackendDrm() = default;
+ ~MinuiBackendDrm() override;
+
+ GRSurface* Init() override;
+ GRSurface* Flip() override;
+ void Blank(bool) override;
+
+ private:
+ void DrmDisableCrtc(int drm_fd, drmModeCrtc* crtc);
+ bool DrmEnableCrtc(int drm_fd, drmModeCrtc* crtc, const std::unique_ptr<GRSurfaceDrm>& surface);
+ void DisableNonMainCrtcs(int fd, drmModeRes* resources, drmModeCrtc* main_crtc);
+ drmModeConnector* FindMainMonitor(int fd, drmModeRes* resources, uint32_t* mode_index);
+
+ std::unique_ptr<GRSurfaceDrm> GRSurfaceDrms[2];
+ int current_buffer{ 0 };
+ drmModeCrtc* main_monitor_crtc{ nullptr };
+ drmModeConnector* main_monitor_connector{ nullptr };
+ int drm_fd{ -1 };
+};
diff --git a/minuitwrp/graphics_fbdev.cpp b/minuitwrp/graphics_fbdev.cpp
index fc5fcf3..499e0ea 100644
--- a/minuitwrp/graphics_fbdev.cpp
+++ b/minuitwrp/graphics_fbdev.cpp
@@ -30,7 +30,7 @@
#include <linux/fb.h>
#include <linux/kd.h>
-#include "minui.h"
+#include "minuitwrp/minui.h"
#include "graphics.h"
#include <pixelflinger/pixelflinger.h>
diff --git a/minuitwrp/graphics_fbdev.h b/minuitwrp/graphics_fbdev.h
new file mode 100644
index 0000000..704d26d
--- /dev/null
+++ b/minuitwrp/graphics_fbdev.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#pragma once
+
+#include <linux/fb.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <memory>
+#include <vector>
+
+#include <android-base/unique_fd.h>
+
+#include "graphics.h"
+#include "minuitwrp/minui.h"
+
+class GRSurfaceFbdev : public GRSurface {
+ public:
+ // Creates and returns a GRSurfaceFbdev instance, or nullptr on error.
+ static std::unique_ptr<GRSurfaceFbdev> Create(size_t width, size_t height, size_t row_bytes,
+ size_t pixel_bytes);
+
+ uint8_t* data() override {
+ return buffer_;
+ }
+
+ protected:
+ using GRSurface::GRSurface;
+
+ private:
+ friend class MinuiBackendFbdev;
+
+ // Points to the start of the buffer: either the mmap'd framebuffer or one allocated in-memory.
+ uint8_t* buffer_{ nullptr };
+};
+
+class MinuiBackendFbdev : public MinuiBackend {
+ public:
+ MinuiBackendFbdev() = default;
+ ~MinuiBackendFbdev() override = default;
+
+ GRSurface* Init() override;
+ GRSurface* Flip() override;
+ void Blank(bool) override;
+
+ private:
+ void SetDisplayedFramebuffer(size_t n);
+
+ std::unique_ptr<GRSurfaceFbdev> gr_framebuffer[2];
+ // Points to the current surface (i.e. one of the two gr_framebuffer's).
+ GRSurfaceFbdev* gr_draw{ nullptr };
+ bool double_buffered;
+ std::vector<uint8_t> memory_buffer;
+ size_t displayed_buffer{ 0 };
+ fb_var_screeninfo vi;
+ android::base::unique_fd fb_fd;
+};
diff --git a/minuitwrp/graphics_utils.cpp b/minuitwrp/graphics_utils.cpp
index 0bc8682..03b333a 100644
--- a/minuitwrp/graphics_utils.cpp
+++ b/minuitwrp/graphics_utils.cpp
@@ -21,7 +21,7 @@
#include <linux/fb.h>
#include <string.h>
-#include "minui.h"
+#include "minuitwrp/minui.h"
struct fb_var_screeninfo vi;
extern GGLSurface gr_mem_surface;
diff --git a/minuitwrp/minui.h b/minuitwrp/include/minuitwrp/minui.h
similarity index 98%
rename from minuitwrp/minui.h
rename to minuitwrp/include/minuitwrp/minui.h
index a6c2a71..f364fe3 100644
--- a/minuitwrp/minui.h
+++ b/minuitwrp/include/minuitwrp/minui.h
@@ -17,7 +17,7 @@
#ifndef _MINUI_H_
#define _MINUI_H_
-#include "../gui/placement.h"
+#include "gui/placement.h"
#include <stdbool.h>
struct GRSurface {
diff --git a/minuitwrp/truetype.hpp b/minuitwrp/include/minuitwrp/truetype.hpp
similarity index 100%
rename from minuitwrp/truetype.hpp
rename to minuitwrp/include/minuitwrp/truetype.hpp
diff --git a/minuitwrp/include/private/resources.h b/minuitwrp/include/private/resources.h
new file mode 100644
index 0000000..047ebe2
--- /dev/null
+++ b/minuitwrp/include/private/resources.h
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <stdio.h>
+
+#include <memory>
+#include <string>
+
+#include <png.h>
+
+// This class handles the PNG file parsing. It also holds the ownership of the PNG pointer and the
+// opened file pointer. Both will be destroyed / closed when this object goes out of scope.
+class PngHandler {
+ public:
+ // Constructs an instance by loading the PNG file from '/res/images/<name>.png', or '<name>'.
+ PngHandler(const std::string& name);
+
+ ~PngHandler();
+
+ png_uint_32 width() const {
+ return width_;
+ }
+
+ png_uint_32 height() const {
+ return height_;
+ }
+
+ png_byte channels() const {
+ return channels_;
+ }
+
+ int bit_depth() const {
+ return bit_depth_;
+ }
+
+ int color_type() const {
+ return color_type_;
+ }
+
+ png_structp png_ptr() const {
+ return png_ptr_;
+ }
+
+ png_infop info_ptr() const {
+ return info_ptr_;
+ }
+
+ int error_code() const {
+ return error_code_;
+ };
+
+ operator bool() const {
+ return error_code_ == 0;
+ }
+
+ private:
+ png_structp png_ptr_{ nullptr };
+ png_infop info_ptr_{ nullptr };
+ png_uint_32 width_;
+ png_uint_32 height_;
+ png_byte channels_;
+ int bit_depth_;
+ int color_type_;
+
+ // The |error_code_| is set to a negative value if an error occurs when opening the png file.
+ int error_code_{ 0 };
+ // After initialization, we'll keep the file pointer open before destruction of PngHandler.
+ std::unique_ptr<FILE, decltype(&fclose)> png_fp_{ nullptr, fclose };
+};
+
+// Overrides the default resource dir, for testing purpose.
+void res_set_resource_dir(const std::string&);
diff --git a/minuitwrp/libminuitwrp_defaults.go b/minuitwrp/libminuitwrp_defaults.go
index 2917098..e56dbf3 100644
--- a/minuitwrp/libminuitwrp_defaults.go
+++ b/minuitwrp/libminuitwrp_defaults.go
@@ -1,304 +1,304 @@
-package libminui_defaults
-
-import (
- "android/soong/android"
- "android/soong/cc"
- "fmt"
- "path/filepath"
- "strings"
-)
-
-func globalFlags(ctx android.BaseContext) []string {
- var cflags []string
-
- if ctx.AConfig().Getenv("TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
- cflags = append(cflags, "-DUSE_QTI_HAPTICS")
- }
-
- if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
- cflags = append(cflags, "-DMSM_BSP")
- }
-
- matches, err := filepath.Glob("system/core/adf/Android.*")
- _ = matches
- if err == nil {
- cflags = append(cflags, "-DHAS_ADF")
- }
-
- if ctx.AConfig().Getenv("TW_NEW_ION_HEAP") == "true" {
- cflags = append(cflags, "-DNEW_ION_HEAP")
- }
-
- matches, err = filepath.Glob("external/libdrm/Android.*")
- if err == nil {
- cflags = append(cflags, "-DHAS_DRM")
- }
-
- if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
- cflags = append(cflags, "-DTW_INCLUDE_JPEG")
- }
-
- if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
- cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
- }
-
- if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
- cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
- }
-
- if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
- cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
- }
-
- if ctx.AConfig().Getenv("RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
- cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
- }
-
- if ctx.AConfig().Getenv("RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
- cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
- }
-
- if ctx.AConfig().Getenv("TWRP_EVENT_LOGGING") == "true" {
- cflags = append(cflags, "-D_EVENT_LOGGING")
- }
-
- var pixelFormat = strings.Replace(ctx.AConfig().Getenv("TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
-
- switch pixelFormat {
- case "RGBA_8888":
- fmt.Println("****************************************************************************)")
- fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
- fmt.Println("****************************************************************************)")
- cflags = append(cflags, "-DRECOVERY_RGBA")
- break
-
- case "RGBX_8888":
- fmt.Println("****************************************************************************)")
- fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
- fmt.Println("****************************************************************************)")
- cflags = append(cflags, "-DRECOVERY_RGBX")
- break
-
- case "BGRA_8888":
- fmt.Println("****************************************************************************)")
- fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
- fmt.Println("****************************************************************************)")
- cflags = append(cflags, "-DRECOVERY_BGRA")
- break
-
- case "RGB_565":
- cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
- break
- }
-
- pixelFormat = strings.Replace(ctx.AConfig().Getenv("TARGET_RECOVERY_PIXEL_FORMAT"), "\"", "", -1)
- switch pixelFormat {
- case "ABGR_8888":
- cflags = append(cflags, "-DRECOVERY_ABGR")
- break
-
- case "RGBX_8888":
- cflags = append(cflags, "-DRECOVERY_RGBX")
- break
-
- case "BGRA_8888":
- cflags = append(cflags, "-DRECOVERY_BGRA")
- break
- }
-
- if ctx.AConfig().Getenv("TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
- cflags = append(cflags, "-DDOVERSCAN_PERCENT="+ctx.AConfig().Getenv("TARGET_RECOVERY_OVERSCAN_PERCENT"))
- } else {
- cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
- }
-
- if ctx.AConfig().Getenv("TW_SCREEN_BLANK_ON_BOOT") == "true" {
- cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
- }
-
- if ctx.AConfig().Getenv("TW_FBIOPAN") == "true" {
- cflags = append(cflags, "-DTW_FBIOPAN")
- }
-
- var tw_rotation = ctx.AConfig().Getenv("TW_ROTATION")
- switch tw_rotation {
- case "0":
- case "90":
- case "180":
- case "270":
- cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
- default:
- if ctx.AConfig().Getenv("BOARD_HAS_FLIPPED_SCREEN") == "true" {
- cflags = append(cflags, "-DTW_ROTATION=180")
- } else {
- cflags = append(cflags, "-DTW_ROTATION=0")
- }
- }
-
- if ctx.AConfig().Getenv("TW_IGNORE_MAJOR_AXIS_0") == "true" {
- cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
- }
-
- if ctx.AConfig().Getenv("TW_IGNORE_MT_POSITION_0") == "true" {
- cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
- }
-
- if ctx.AConfig().Getenv("TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
- cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
- }
-
- if ctx.AConfig().Getenv("TW_INPUT_BLACKLIST") != "" {
- cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+ctx.AConfig().Getenv("TW_INPUT_BLACKLIST"))
- }
-
- if ctx.AConfig().Getenv("TW_WHITELIST_INPUT") != "" {
- cflags = append(cflags, "-DWHITELIST_INPUT="+ctx.AConfig().Getenv("TW_WHITELIST_INPUT"))
- }
-
- if ctx.AConfig().Getenv("TW_HAPTICS_TSPDRV") == "true" {
- cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
- }
-
- cflags = append(cflags, "-DTWRES="+ctx.AConfig().Getenv("TWRES_PATH"))
- return cflags
-}
-
-func globalSrcs(ctx android.BaseContext) []string {
- var srcs []string
-
- if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
- srcs = append(srcs, "graphics_overlay.cpp")
- }
-
- matches, err := filepath.Glob("system/core/adf/Android.*")
- _ = matches
- if err == nil {
- srcs = append(srcs, "graphics_adf.cpp")
- }
-
- matches, err = filepath.Glob("external/libdrm/Android.*")
- if err == nil {
- srcs = append(srcs, "graphics_drm.cpp")
- }
-
- if ctx.AConfig().Getenv("TW_HAPTICS_TSPDRV") == "true" {
- srcs = append(srcs, "tspdrv.cpp")
- }
- return srcs
-}
-
-func globalIncludes(ctx android.BaseContext) []string {
- var includes []string
-
- if ctx.AConfig().Getenv("TW_INCLUDE_CRYPTO") != "" {
- includes = append(includes, "bootable/recovery/crypto/fscrypt")
- }
-
- if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
- if ctx.AConfig().Getenv("TARGET_PREBUILT_KERNEL") != "" {
- includes = append(includes, ctx.AConfig().Getenv("TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
- } else {
- if ctx.AConfig().Getenv("TARGET_CUSTOM_KERNEL_HEADERS") != "" {
- includes = append(includes, "bootable/recovery/minuitwrp")
- } else {
- includes = append(includes, ctx.AConfig().Getenv("TARGET_CUSTOM_KERNEL_HEADERS"))
- }
- }
- } else {
- includes = append(includes, "bootable/recovery/minuitwrp")
- }
-
- if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
- includes = append(includes, "external/jpeg")
- }
-
- return includes
-}
-
-func globalStaticLibs(ctx android.BaseContext) []string {
- var staticLibs []string
-
- matches, err := filepath.Glob("system/core/adf/Android.*")
- _ = matches
- if err == nil {
- staticLibs = append(staticLibs, "libadf")
- }
-
- matches, err = filepath.Glob("external/libdrm/Android.*")
- if err == nil {
- matches, err = filepath.Glob("external/libdrm/Android.common.mk")
- if err != nil {
- staticLibs = append(staticLibs, "libdrm_platform")
- } else {
- staticLibs = append(staticLibs, "libdrm")
- }
- }
-
- return staticLibs
-}
-
-func globalSharedLibs(ctx android.BaseContext) []string {
- var sharedLibs []string
-
- if ctx.AConfig().Getenv("TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
- sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
- sharedLibs = append(sharedLibs, "libhidlbase")
- }
-
- if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
- sharedLibs = append(sharedLibs, "libjpeg")
- }
- return sharedLibs
-}
-
-func globalRequiredModules(ctx android.BaseContext) []string {
- var requiredModules []string
-
- if ctx.AConfig().Getenv("TARGET_PREBUILT_KERNEL") != "" {
- var kernelDir = ctx.AConfig().Getenv("TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
- requiredModules = append(requiredModules, kernelDir)
- }
- return requiredModules
-}
-
-func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
- type props struct {
- Target struct {
- Android struct {
- Cflags []string
- Enabled *bool
- }
- }
- Cflags []string
- Srcs []string
- Include_dirs []string
- Static_libs []string
- Shared_libs []string
- Required []string
- }
-
- p := &props{}
- p.Cflags = globalFlags(ctx)
- s := globalSrcs(ctx)
- p.Srcs = s
- i := globalIncludes(ctx)
- p.Include_dirs = i
- staticLibs := globalStaticLibs(ctx)
- p.Static_libs = staticLibs
- sharedLibs := globalSharedLibs(ctx)
- p.Shared_libs = sharedLibs
- requiredModules := globalRequiredModules(ctx)
- p.Required = requiredModules
- ctx.AppendProperties(p)
-}
-
-func init() {
- android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
-}
-
-func libMinuiTwrpDefaultsFactory() android.Module {
- module := cc.DefaultsFactory()
- android.AddLoadHook(module, libMinuiTwrpDefaults)
-
- return module
-}
+package twrp
+
+import (
+ "android/soong/android"
+ "android/soong/cc"
+ "fmt"
+ "path/filepath"
+ "strings"
+)
+
+func globalFlags(ctx android.BaseContext) []string {
+ var cflags []string
+
+ if ctx.AConfig().Getenv("TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
+ cflags = append(cflags, "-DUSE_QTI_HAPTICS")
+ }
+
+ if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
+ cflags = append(cflags, "-DMSM_BSP")
+ }
+
+ matches, err := filepath.Glob("system/core/adf/Android.*")
+ _ = matches
+ if err == nil {
+ cflags = append(cflags, "-DHAS_ADF")
+ }
+
+ if ctx.AConfig().Getenv("TW_NEW_ION_HEAP") == "true" {
+ cflags = append(cflags, "-DNEW_ION_HEAP")
+ }
+
+ matches, err = filepath.Glob("external/libdrm/Android.*")
+ _ = matches
+ if err == nil {
+ cflags = append(cflags, "-DHAS_DRM")
+ }
+
+ if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
+ cflags = append(cflags, "-DTW_INCLUDE_JPEG")
+ }
+
+ if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_SWAP_XY") == "true" {
+ cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_SWAP_XY")
+ }
+
+ if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_FLIP_X") == "true" {
+ cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_X")
+ }
+
+ if ctx.AConfig().Getenv("RECOVERY_TOUCHSCREEN_FLIP_Y") == "true" {
+ cflags = append(cflags, "-DRECOVERY_TOUCHSCREEN_FLIP_Y")
+ }
+
+ if ctx.AConfig().Getenv("RECOVERY_GRAPHICS_FORCE_USE_LINELENGTH") == "true" {
+ cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_USE_LINELENGTH")
+ }
+
+ if ctx.AConfig().Getenv("RECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER") == "true" {
+ cflags = append(cflags, "-DRECOVERY_GRAPHICS_FORCE_SINGLE_BUFFER")
+ }
+
+ if ctx.AConfig().Getenv("TWRP_EVENT_LOGGING") == "true" {
+ cflags = append(cflags, "-D_EVENT_LOGGING")
+ }
+
+ var pixelFormat = strings.Replace(ctx.AConfig().Getenv("TARGET_RECOVERY_FORCE_PIXEL_FORMAT"), "\"", "", -1)
+
+ switch pixelFormat {
+ case "RGBA_8888":
+ fmt.Println("****************************************************************************)")
+ fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBA_8888 not implemented yet *)")
+ fmt.Println("****************************************************************************)")
+ cflags = append(cflags, "-DRECOVERY_RGBA")
+ break
+
+ case "RGBX_8888":
+ fmt.Println("****************************************************************************)")
+ fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := RGBX_8888 not implemented yet *)")
+ fmt.Println("****************************************************************************)")
+ cflags = append(cflags, "-DRECOVERY_RGBX")
+ break
+
+ case "BGRA_8888":
+ fmt.Println("****************************************************************************)")
+ fmt.Println("* TARGET_RECOVERY_FORCE_PIXEL_FORMAT := BGRA_8888 not implemented yet *)")
+ fmt.Println("****************************************************************************)")
+ cflags = append(cflags, "-DRECOVERY_BGRA")
+ break
+
+ case "RGB_565":
+ cflags = append(cflags, "-DRECOVERY_FORCE_RGB_565")
+ break
+ }
+
+ pixelFormat = strings.Replace(ctx.AConfig().Getenv("TWRP_EVENT_LOGGING"), "\"", "", -1)
+ switch pixelFormat {
+ case "ABGR_8888":
+ cflags = append(cflags, "-DRECOVERY_ABGR")
+ break
+
+ case "RGBX_8888":
+ cflags = append(cflags, "-DRECOVERY_RGBX")
+ break
+
+ case "BGRA_8888":
+ cflags = append(cflags, "-DRECOVERY_BGRA")
+ break
+ }
+
+ if ctx.AConfig().Getenv("TARGET_RECOVERY_OVERSCAN_PERCENT") != "" {
+ cflags = append(cflags, "-DDOVERSCAN_PERCENT="+ctx.AConfig().Getenv("TARGET_RECOVERY_OVERSCAN_PERCENT"))
+ } else {
+ cflags = append(cflags, "-DOVERSCAN_PERCENT=0")
+ }
+
+ if ctx.AConfig().Getenv("TW_SCREEN_BLANK_ON_BOOT") == "true" {
+ cflags = append(cflags, "-DTW_SCREEN_BLANK_ON_BOOT")
+ }
+
+ if ctx.AConfig().Getenv("TW_FBIOPAN") == "true" {
+ cflags = append(cflags, "-DTW_FBIOPAN")
+ }
+
+ var tw_rotation = ctx.AConfig().Getenv("TW_ROTATION")
+ switch tw_rotation {
+ case "0":
+ case "90":
+ case "180":
+ case "270":
+ cflags = append(cflags, "-DTW_ROTATION="+tw_rotation)
+ default:
+ if ctx.AConfig().Getenv("BOARD_HAS_FLIPPED_SCREEN") == "true" {
+ cflags = append(cflags, "-DTW_ROTATION=180")
+ } else {
+ cflags = append(cflags, "-DTW_ROTATION=0")
+ }
+ }
+
+ if ctx.AConfig().Getenv("TW_IGNORE_MAJOR_AXIS_0") == "true" {
+ cflags = append(cflags, "-DTW_IGNORE_MAJOR_AXIS_0")
+ }
+
+ if ctx.AConfig().Getenv("TW_IGNORE_MT_POSITION_0") == "true" {
+ cflags = append(cflags, "-DTW_IGNORE_MT_POSITION_0")
+ }
+
+ if ctx.AConfig().Getenv("TW_IGNORE_ABS_MT_TRACKING_ID") == "true" {
+ cflags = append(cflags, "-DTW_IGNORE_ABS_MT_TRACKING_ID")
+ }
+
+ if ctx.AConfig().Getenv("TW_INPUT_BLACKLIST") != "" {
+ cflags = append(cflags, "-DTW_INPUT_BLACKLIST="+ctx.AConfig().Getenv("TW_INPUT_BLACKLIST"))
+ }
+
+ if ctx.AConfig().Getenv("TW_WHITELIST_INPUT") != "" {
+ cflags = append(cflags, "-DWHITELIST_INPUT="+ctx.AConfig().Getenv("TW_WHITELIST_INPUT"))
+ }
+
+ if ctx.AConfig().Getenv("TW_HAPTICS_TSPDRV") == "true" {
+ cflags = append(cflags, "-DTW_HAPTICS_TSPDRV")
+ }
+
+ return cflags
+}
+
+func globalSrcs(ctx android.BaseContext) []string {
+ var srcs []string
+
+ if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
+ srcs = append(srcs, "graphics_overlay.cpp")
+ }
+
+ matches, err := filepath.Glob("system/core/adf/Android.*")
+ _ = matches
+ if err == nil {
+ srcs = append(srcs, "graphics_adf.cpp")
+ }
+
+ matches, err = filepath.Glob("external/libdrm/Android.*")
+ if err == nil {
+ srcs = append(srcs, "graphics_drm.cpp")
+ }
+
+ if ctx.AConfig().Getenv("TW_HAPTICS_TSPDRV") == "true" {
+ srcs = append(srcs, "tspdrv.cpp")
+ }
+ return srcs
+}
+
+func globalIncludes(ctx android.BaseContext) []string {
+ var includes []string
+
+ if ctx.AConfig().Getenv("TW_INCLUDE_CRYPTO") != "" {
+ includes = append(includes, "bootable/recovery/crypto/fscrypt")
+ }
+
+ if ctx.AConfig().Getenv("TW_TARGET_USES_QCOM_BSP") == "true" {
+ if ctx.AConfig().Getenv("TARGET_PREBUILT_KERNEL") != "" {
+ includes = append(includes, ctx.AConfig().Getenv("TARGET_OUT_INTERMEDIATES")+"/KERNEL_OBJ/usr/include")
+ } else {
+ if ctx.AConfig().Getenv("TARGET_CUSTOM_KERNEL_HEADERS") != "" {
+ includes = append(includes, "bootable/recovery/minuitwrp")
+ } else {
+ includes = append(includes, ctx.AConfig().Getenv("TARGET_CUSTOM_KERNEL_HEADERS"))
+ }
+ }
+ } else {
+ includes = append(includes, "bootable/recovery/minuitwrp")
+ }
+
+ if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
+ includes = append(includes, "external/jpeg")
+ }
+
+ return includes
+}
+
+func globalStaticLibs(ctx android.BaseContext) []string {
+ var staticLibs []string
+
+ matches, err := filepath.Glob("system/core/adf/Android.*")
+ _ = matches
+ if err == nil {
+ staticLibs = append(staticLibs, "libadf")
+ }
+
+ matches, err = filepath.Glob("external/libdrm/Android.*")
+ if err == nil {
+ matches, err = filepath.Glob("external/libdrm/Android.common.mk")
+ if err != nil {
+ staticLibs = append(staticLibs, "libdrm_platform")
+ } else {
+ staticLibs = append(staticLibs, "libdrm")
+ }
+ }
+
+ return staticLibs
+}
+
+func globalSharedLibs(ctx android.BaseContext) []string {
+ var sharedLibs []string
+
+ if ctx.AConfig().Getenv("TW_SUPPORT_INPUT_1_2_HAPTICS") == "true" {
+ sharedLibs = append(sharedLibs, "android.hardware.vibrator@1.2")
+ sharedLibs = append(sharedLibs, "libhidlbase")
+ }
+
+ if ctx.AConfig().Getenv("TW_INCLUDE_JPEG") != "" {
+ sharedLibs = append(sharedLibs, "libjpeg")
+ }
+ return sharedLibs
+}
+
+func globalRequiredModules(ctx android.BaseContext) []string {
+ var requiredModules []string
+
+ if ctx.AConfig().Getenv("TARGET_PREBUILT_KERNEL") != "" {
+ var kernelDir = ctx.AConfig().Getenv("TARGET_OUT_INTERMEDIATES") + ")/KERNEL_OBJ/usr"
+ requiredModules = append(requiredModules, kernelDir)
+ }
+ return requiredModules
+}
+
+func libMinuiTwrpDefaults(ctx android.LoadHookContext) {
+ type props struct {
+ Target struct {
+ Android struct {
+ Cflags []string
+ Enabled *bool
+ }
+ }
+ Cflags []string
+ Srcs []string
+ Include_dirs []string
+ Static_libs []string
+ Shared_libs []string
+ Required []string
+ }
+
+ p := &props{}
+ p.Cflags = globalFlags(ctx)
+ s := globalSrcs(ctx)
+ p.Srcs = s
+ i := globalIncludes(ctx)
+ p.Include_dirs = i
+ staticLibs := globalStaticLibs(ctx)
+ p.Static_libs = staticLibs
+ sharedLibs := globalSharedLibs(ctx)
+ p.Shared_libs = sharedLibs
+ requiredModules := globalRequiredModules(ctx)
+ p.Required = requiredModules
+ ctx.AppendProperties(p)
+}
+
+func init() {
+ android.RegisterModuleType("libminuitwrp_defaults", libMinuiTwrpDefaultsFactory)
+}
+
+func libMinuiTwrpDefaultsFactory() android.Module {
+ module := cc.DefaultsFactory()
+ android.AddLoadHook(module, libMinuiTwrpDefaults)
+
+ return module
+}
diff --git a/minuitwrp/resources.cpp b/minuitwrp/resources.cpp
index c4325e4..f3abd59 100644
--- a/minuitwrp/resources.cpp
+++ b/minuitwrp/resources.cpp
@@ -36,7 +36,7 @@
#include "jpeglib.h"
}
#endif
-#include "minui.h"
+#include "minuitwrp/minui.h"
#define SURFACE_DATA_ALIGNMENT 8
@@ -355,7 +355,6 @@
int res_create_surface(const char* name, gr_surface* pSurface) {
int ret;
-
if (!name) return -1;
#ifdef TW_INCLUDE_JPEG
@@ -363,7 +362,7 @@
return res_create_surface_jpg(name,pSurface);
#endif
- ret = res_create_surface_png(name,pSurface);
+ ret = res_create_surface_png(name, pSurface);
#ifdef TW_INCLUDE_JPEG
if (ret < 0)
ret = res_create_surface_jpg(name,pSurface);
diff --git a/minuitwrp/truetype.cpp b/minuitwrp/truetype.cpp
index 9ab8c7a..d224fbb 100644
--- a/minuitwrp/truetype.cpp
+++ b/minuitwrp/truetype.cpp
@@ -26,7 +26,7 @@
#include <pthread.h>
#include <algorithm>
#include <string>
-#include "truetype.hpp"
+#include "minuitwrp/truetype.hpp"
extern unsigned int gr_rotation;