diff --git a/power/performance.h b/power/performance.h index 5deddd4..cfa585d 100644 --- a/power/performance.h +++ b/power/performance.h @@ -41,6 +41,22 @@ extern "C" { #define VENDOR_HINT_DISPLAY_OFF 0x00001040 #define VENDOR_HINT_DISPLAY_ON 0x00001041 +#define VENDOR_HINT_FIRST_LAUNCH_BOOST 0x00001081 +#define VENDOR_HINT_SCROLL_BOOST 0x00001080 + +enum { + LAUNCH_BOOST_V1 = 1, + LAUNCH_BOOST_V2 = 2, + LAUNCH_BOOST_V3 = 3 +}; + +enum { + SCROLL_VERTICAL = 1, + SCROLL_HORIZONTAL = 2, + SCROLL_PANEL_VIEW = 3, + SCROLL_PREFILING = 4 +}; + enum SCREEN_DISPLAY_TYPE { DISPLAY_OFF = 0x00FF, }; diff --git a/power/power-710.c b/power/power-710.c index 3a33e43..2df2ed7 100644 --- a/power/power-710.c +++ b/power/power-710.c @@ -51,6 +51,10 @@ #define CHECK_HANDLE(x) ((x) > 0) #define NUM_PERF_MODES 3 +const int kMaxInteractiveDuration = 5000; /* ms */ +const int kMinInteractiveDuration = 100; /* ms */ +const int kMinFlingDuration = 1500; /* ms */ + typedef enum { NORMAL_MODE = 0, SUSTAINED_MODE = 1, @@ -187,8 +191,53 @@ static int process_video_encode_hint(void* metadata) { return HINT_NONE; } -/* Declare function before use */ -void interaction(int duration, int num_args, int opt_list[]); +static int process_activity_launch_hint(void* data) { + if (current_mode != NORMAL_MODE) { + ALOGV("%s: ignoring due to other active perf hints", __func__); + } else { + perf_hint_enable_with_type(VENDOR_HINT_FIRST_LAUNCH_BOOST, -1, LAUNCH_BOOST_V1); + } + return HINT_HANDLED; +} + +static int process_interaction_hint(void* data) { + struct timeval cur_boost_timeval = {0, 0}; + static unsigned long long previous_boost_time = 0; + static unsigned long long previous_duration = 0; + unsigned long long cur_boost_time; + double elapsed_time; + int duration = kMinInteractiveDuration; + + if (current_mode != NORMAL_MODE) { + ALOGV("%s: ignoring due to other active perf hints", __func__); + return HINT_HANDLED; + } + + if (data) { + int input_duration = *((int*)data); + if (input_duration > duration) { + duration = (input_duration > kMaxInteractiveDuration) ? + kMaxInteractiveDuration : input_duration; + } + } + + gettimeofday(&cur_boost_timeval, NULL); + cur_boost_time = cur_boost_timeval.tv_sec * 1000000 + cur_boost_timeval.tv_usec; + elapsed_time = (double) (cur_boost_time - previous_boost_time); + // don't hint if previous hint's duration covers this hint's duration + if ((previous_duration * 1000) > (elapsed_time + duration * 1000)) { + return HINT_HANDLED; + } + previous_boost_time = cur_boost_time; + previous_duration = duration; + + if (duration >= kMinFlingDuration) { + perf_hint_enable_with_type(VENDOR_HINT_SCROLL_BOOST, -1, SCROLL_PREFILING); + } else { + perf_hint_enable_with_type(VENDOR_HINT_SCROLL_BOOST, duration, SCROLL_VERTICAL); + } + return HINT_HANDLED; +} int power_hint_override(struct power_module* module, power_hint_t hint, void* data) { int ret_val = HINT_NONE; @@ -202,12 +251,12 @@ int power_hint_override(struct power_module* module, power_hint_t hint, void* da case POWER_HINT_VR_MODE: ret_val = process_perf_hint(data, VR_MODE); break; - case POWER_HINT_INTERACTION: { - int resources[] = {0x40800100, 0x514}; - int duration = 100; - interaction(duration, sizeof(resources) / sizeof(resources[0]), resources); - ret_val = HINT_HANDLED; - } break; + case POWER_HINT_INTERACTION: + ret_val = process_interaction_hint(data); + break; + case POWER_HINT_LAUNCH: + ret_val = process_activity_launch_hint(data); + break; default: break; } diff --git a/power/utils.c b/power/utils.c index 5153701..21aac0f 100644 --- a/power/utils.c +++ b/power/utils.c @@ -233,6 +233,19 @@ int perf_hint_enable(int hint_id, int duration) { return lock_handle; } +// same as perf_hint_enable, but with the ability to choose the type +int perf_hint_enable_with_type(int hint_id, int duration, int type) { + int lock_handle = 0; + + if (qcopt_handle) { + if (perf_hint) { + lock_handle = perf_hint(hint_id, NULL, duration, type); + if (lock_handle == -1) ALOGE("Failed to acquire lock."); + } + } + return lock_handle; +} + void release_request(int lock_handle) { if (qcopt_handle && perf_lock_rel) perf_lock_rel(lock_handle); } diff --git a/power/utils.h b/power/utils.h index b2d5d2c..12d3001 100644 --- a/power/utils.h +++ b/power/utils.h @@ -44,3 +44,4 @@ void undo_hint_action(int hint_id); void release_request(int lock_handle); int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]); int perf_hint_enable(int hint_id, int duration); +int perf_hint_enable_with_type(int hint_id, int duration, int type);