Merge Android R

Bug: 168057903
Merged-In: Ib76a3f938a240498c6201b01f8b1281624618038
Change-Id: I0470fcebdd6d5921b8d9e6e3ee55f9b72c8c695e
diff --git a/msm8909/gpu_tonemapper/Android.mk b/msm8909/gpu_tonemapper/Android.mk
index 8b7a866..8da0628 100644
--- a/msm8909/gpu_tonemapper/Android.mk
+++ b/msm8909/gpu_tonemapper/Android.mk
@@ -17,7 +17,7 @@
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
 
 LOCAL_CFLAGS              := $(version_flag) -Wno-missing-field-initializers -Wall \
-                             -Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\"
+                             -Wno-unused-parameter -DLOG_TAG=\"GPU_TONEMAPPER\"
 
 LOCAL_SRC_FILES           := TonemapFactory.cpp \
                              glengine.cpp \
diff --git a/msm8909/sdm/libs/hwc/Android.mk b/msm8909/sdm/libs/hwc/Android.mk
index 4e52424..6b7aa6c 100644
--- a/msm8909/sdm/libs/hwc/Android.mk
+++ b/msm8909/sdm/libs/hwc/Android.mk
@@ -11,7 +11,7 @@
 LOCAL_HEADER_LIBRARIES        := display_headers
 
 LOCAL_CFLAGS                  := $(common_flags) -Wno-missing-field-initializers -Wno-unused-parameter \
-                                 -std=c++11 -fcolor-diagnostics -Wno-sign-conversion -DLOG_TAG=\"SDM\"
+                                 -fcolor-diagnostics -Wno-sign-conversion -DLOG_TAG=\"SDM\"
 LOCAL_CLANG                   := true
 
 LOCAL_SHARED_LIBRARIES        := libsdmcore libqservice libbinder libhardware libhardware_legacy \
diff --git a/msm8909/sdm/libs/hwc2/Android.mk b/msm8909/sdm/libs/hwc2/Android.mk
index cd84214..22e101b 100644
--- a/msm8909/sdm/libs/hwc2/Android.mk
+++ b/msm8909/sdm/libs/hwc2/Android.mk
@@ -12,7 +12,7 @@
 LOCAL_HEADER_LIBRARIES        := display_headers
 
 LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
-                                 -std=c++11 -fcolor-diagnostics\
+                                 -fcolor-diagnostics\
                                  -DLOG_TAG=\"SDM\" $(common_flags) \
                                  -I $(display_top)/sdm/libs/hwc
 ifeq ($(TARGET_EXCLUDES_DISPLAY_PP), true)
diff --git a/msm8909w_3100/gpu_tonemapper/Android.mk b/msm8909w_3100/gpu_tonemapper/Android.mk
index a2471e5..20e86b1 100644
--- a/msm8909w_3100/gpu_tonemapper/Android.mk
+++ b/msm8909w_3100/gpu_tonemapper/Android.mk
@@ -15,7 +15,7 @@
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
 
 LOCAL_CFLAGS              := $(version_flag) -Wno-missing-field-initializers -Wall \
-                             -Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\"
+                             -Wno-unused-parameter -DLOG_TAG=\"GPU_TONEMAPPER\"
 
 LOCAL_SRC_FILES           := TonemapFactory.cpp \
                              glengine.cpp \
diff --git a/msm8909w_3100/sdm/libs/hwc/Android.mk b/msm8909w_3100/sdm/libs/hwc/Android.mk
index 4e52424..6b7aa6c 100644
--- a/msm8909w_3100/sdm/libs/hwc/Android.mk
+++ b/msm8909w_3100/sdm/libs/hwc/Android.mk
@@ -11,7 +11,7 @@
 LOCAL_HEADER_LIBRARIES        := display_headers
 
 LOCAL_CFLAGS                  := $(common_flags) -Wno-missing-field-initializers -Wno-unused-parameter \
-                                 -std=c++11 -fcolor-diagnostics -Wno-sign-conversion -DLOG_TAG=\"SDM\"
+                                 -fcolor-diagnostics -Wno-sign-conversion -DLOG_TAG=\"SDM\"
 LOCAL_CLANG                   := true
 
 LOCAL_SHARED_LIBRARIES        := libsdmcore libqservice libbinder libhardware libhardware_legacy \
diff --git a/msm8909w_3100/sdm/libs/hwc2/Android.mk b/msm8909w_3100/sdm/libs/hwc2/Android.mk
index ea929d3..beec1a8 100644
--- a/msm8909w_3100/sdm/libs/hwc2/Android.mk
+++ b/msm8909w_3100/sdm/libs/hwc2/Android.mk
@@ -12,7 +12,7 @@
 LOCAL_HEADER_LIBRARIES        := display_headers
 
 LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
-                                 -std=c++11 -fcolor-diagnostics\
+                                 -fcolor-diagnostics\
                                  -DLOG_TAG=\"SDM\" $(common_flags) \
                                  -I $(display_top)/sdm/libs/hwc
 
diff --git a/msm8998/gpu_tonemapper/Android.mk b/msm8998/gpu_tonemapper/Android.mk
index fcb66cb..ea1d2e9 100644
--- a/msm8998/gpu_tonemapper/Android.mk
+++ b/msm8998/gpu_tonemapper/Android.mk
@@ -17,7 +17,7 @@
 LOCAL_SHARED_LIBRARIES    := libEGL libGLESv2 libGLESv3 libui libutils liblog
 
 LOCAL_CFLAGS              := $(version_flag) -Wno-missing-field-initializers -Wall \
-                             -Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\"
+                             -Wno-unused-parameter -DLOG_TAG=\"GPU_TONEMAPPER\"
 
 LOCAL_SRC_FILES           := TonemapFactory.cpp \
                              glengine.cpp \
diff --git a/msm8998/libqdutils/profiler.cpp b/msm8998/libqdutils/profiler.cpp
index 810b019..83f549d 100644
--- a/msm8998/libqdutils/profiler.cpp
+++ b/msm8998/libqdutils/profiler.cpp
@@ -185,7 +185,7 @@
     }
     else if (debug_fps_metadata_t::DFM_TIME == debug_fps_metadata.type) {
         debug_fps_metadata.time_elapsed += (float)((float)diff/1000.0);
-        if (debug_fps_metadata.time_elapsed >= debug_fps_metadata.time_period) {
+        if (debug_fps_metadata.time_elapsed >= (float)debug_fps_metadata.time_period) {
             float fps = float(1000.0 * debug_fps_metadata.curr_frame/
                                             debug_fps_metadata.time_elapsed);
             print_fps(fps);
diff --git a/msm8998/sdm/libs/core/display_base.cpp b/msm8998/sdm/libs/core/display_base.cpp
index 6f2966f..257d462 100644
--- a/msm8998/sdm/libs/core/display_base.cpp
+++ b/msm8998/sdm/libs/core/display_base.cpp
@@ -201,8 +201,8 @@
   auto gpu_target_layer_dst_xpixels = out_rect.right - out_rect.left;
   auto gpu_target_layer_dst_ypixels = out_rect.bottom - out_rect.top;
 
-  if (gpu_target_layer_dst_xpixels > mixer_attributes_.width ||
-    gpu_target_layer_dst_ypixels > mixer_attributes_.height) {
+  if (gpu_target_layer_dst_xpixels > layer_mixer_width ||
+    gpu_target_layer_dst_ypixels > layer_mixer_height) {
     DLOGE("GPU target layer dst rect is not with in limits gpu wxh %fx%f, mixer wxh %dx%d",
                   gpu_target_layer_dst_xpixels, gpu_target_layer_dst_ypixels,
                   mixer_attributes_.width, mixer_attributes_.height);
@@ -1179,7 +1179,7 @@
 
     // Align the width and height according to fb's aspect ratio
     *new_mixer_width = FloorToMultipleOf(UINT32((FLOAT(fb_width) / FLOAT(fb_height)) *
-                                         layer_height), align_x);
+                                         FLOAT(layer_height)), align_x);
     *new_mixer_height = FloorToMultipleOf(layer_height, align_y);
 
     LayerRect dst_domain = {0.0f, 0.0f, FLOAT(*new_mixer_width), FLOAT(*new_mixer_height)};
diff --git a/msm8998/sdm/libs/core/display_primary.cpp b/msm8998/sdm/libs/core/display_primary.cpp
index 572dd00..35fdfb0 100644
--- a/msm8998/sdm/libs/core/display_primary.cpp
+++ b/msm8998/sdm/libs/core/display_primary.cpp
@@ -94,8 +94,8 @@
 
   if (needs_hv_flip) {
     DisplayBase::GetFrameBufferConfig(&variable_info);
-    src_domain.right = variable_info.x_pixels;
-    src_domain.bottom = variable_info.y_pixels;
+    src_domain.right = static_cast<float>(variable_info.x_pixels);
+    src_domain.bottom = static_cast<float>(variable_info.y_pixels);
     panel_transform.flip_horizontal = hw_panel_info_.panel_orientation.flip_horizontal;
     panel_transform.flip_vertical = hw_panel_info_.panel_orientation.flip_vertical;
 
diff --git a/msm8998/sdm/libs/core/drm/hw_device_drm.cpp b/msm8998/sdm/libs/core/drm/hw_device_drm.cpp
index af7ce6e..f8bf762 100644
--- a/msm8998/sdm/libs/core/drm/hw_device_drm.cpp
+++ b/msm8998/sdm/libs/core/drm/hw_device_drm.cpp
@@ -760,7 +760,7 @@
 
   float scale_x = FLOAT(display_attributes_.x_pixels) / FLOAT(mixer_attributes.width);
   float scale_y = FLOAT(display_attributes_.y_pixels) / FLOAT(mixer_attributes.height);
-  float max_scale_up = hw_resource_.hw_dest_scalar_info.max_scale_up;
+  float max_scale_up = FLOAT(hw_resource_.hw_dest_scalar_info.max_scale_up);
   if (scale_x > max_scale_up || scale_y > max_scale_up) {
     DLOGW(
         "Up scaling ratio exceeds for destination scalar upscale limit scale_x %f scale_y %f "
diff --git a/msm8998/sdm/libs/core/fb/hw_device.cpp b/msm8998/sdm/libs/core/fb/hw_device.cpp
index 92dd826..c62917d 100644
--- a/msm8998/sdm/libs/core/fb/hw_device.cpp
+++ b/msm8998/sdm/libs/core/fb/hw_device.cpp
@@ -1333,7 +1333,7 @@
 
   float scale_x = FLOAT(display_attributes_.x_pixels) / FLOAT(mixer_attributes.width);
   float scale_y = FLOAT(display_attributes_.y_pixels) / FLOAT(mixer_attributes.height);
-  float max_scale_up = hw_resource_.hw_dest_scalar_info.max_scale_up;
+  float max_scale_up = FLOAT(hw_resource_.hw_dest_scalar_info.max_scale_up);
   if (scale_x > max_scale_up || scale_y > max_scale_up) {
     DLOGW_IF(kTagDriverConfig, "Up scaling ratio exceeds for destination scalar upscale " \
              "limit scale_x %f scale_y %f max_scale_up %f", scale_x, scale_y, max_scale_up);
diff --git a/msm8998/sdm/libs/core/resource_default.cpp b/msm8998/sdm/libs/core/resource_default.cpp
index 31d8704..bf06153 100644
--- a/msm8998/sdm/libs/core/resource_default.cpp
+++ b/msm8998/sdm/libs/core/resource_default.cpp
@@ -469,7 +469,7 @@
   float dst_width = dst_rect.right - dst_rect.left;
 
   // Layer cannot qualify for SrcSplit if source or destination width exceeds max pipe width.
-  if ((src_width > hw_res_info_.max_pipe_width) || (dst_width > hw_res_info_.max_pipe_width)) {
+  if ((src_width > FLOAT(hw_res_info_.max_pipe_width)) || (dst_width > FLOAT(hw_res_info_.max_pipe_width))) {
     SplitRect(src_rect, dst_rect, &left_pipe->src_roi, &left_pipe->dst_roi, &right_pipe->src_roi,
               &right_pipe->dst_roi);
     left_pipe->valid = true;
diff --git a/msm8998/sdm/libs/core/strategy.cpp b/msm8998/sdm/libs/core/strategy.cpp
index 8398bbd..6cf40b8 100644
--- a/msm8998/sdm/libs/core/strategy.cpp
+++ b/msm8998/sdm/libs/core/strategy.cpp
@@ -174,8 +174,8 @@
     return;
   }
 
-  float layer_mixer_width = mixer_attributes_.width;
-  float layer_mixer_height = mixer_attributes_.height;
+  float layer_mixer_width = FLOAT(mixer_attributes_.width);
+  float layer_mixer_height = FLOAT(mixer_attributes_.height);
 
   if (!hw_resource_info_.is_src_split && display_attributes_.is_device_split) {
     split_display = true;
diff --git a/msm8998/sdm/libs/hwc2/hwc_callbacks.cpp b/msm8998/sdm/libs/hwc2/hwc_callbacks.cpp
index c52632a..e12e057 100644
--- a/msm8998/sdm/libs/hwc2/hwc_callbacks.cpp
+++ b/msm8998/sdm/libs/hwc2/hwc_callbacks.cpp
@@ -35,18 +35,21 @@
 namespace sdm {
 
 void HWCCallbacks::Hotplug(hwc2_display_t display, HWC2::Connection state) {
+  std::lock_guard<std::mutex> hotplug_lock(hotplug_mutex_);
   if (hotplug_) {
     hotplug_(hotplug_data_, display, INT32(state));
   }
 }
 
 void HWCCallbacks::Refresh(hwc2_display_t display) {
+  std::lock_guard<std::mutex> refresh_lock(refresh_mutex_);
   if (refresh_) {
     refresh_(refresh_data_, display);
   }
 }
 
 void HWCCallbacks::Vsync(hwc2_display_t display, int64_t timestamp) {
+  std::lock_guard<std::mutex> vsync_lock(vsync_mutex_);
   if (vsync_) {
     DTRACE_SCOPED();
     vsync_(vsync_data_, display, timestamp);
@@ -56,18 +59,21 @@
 HWC2::Error HWCCallbacks::Register(HWC2::Callback descriptor, hwc2_callback_data_t callback_data,
                                    hwc2_function_pointer_t pointer) {
   switch (descriptor) {
-    case HWC2::Callback::Hotplug:
+    case HWC2::Callback::Hotplug: {
+      std::lock_guard<std::mutex> hotplug_lock(hotplug_mutex_);
       hotplug_data_ = callback_data;
       hotplug_ = reinterpret_cast<HWC2_PFN_HOTPLUG>(pointer);
-      break;
-    case HWC2::Callback::Refresh:
+    } break;
+    case HWC2::Callback::Refresh: {
+      std::lock_guard<std::mutex> refresh_lock(refresh_mutex_);
       refresh_data_ = callback_data;
       refresh_ = reinterpret_cast<HWC2_PFN_REFRESH>(pointer);
-      break;
-    case HWC2::Callback::Vsync:
+    } break;
+    case HWC2::Callback::Vsync: {
+      std::lock_guard<std::mutex> vsync_lock(vsync_mutex_);
       vsync_data_ = callback_data;
       vsync_ = reinterpret_cast<HWC2_PFN_VSYNC>(pointer);
-      break;
+    } break;
     default:
       return HWC2::Error::BadParameter;
   }
diff --git a/msm8998/sdm/libs/hwc2/hwc_callbacks.h b/msm8998/sdm/libs/hwc2/hwc_callbacks.h
index 015bf5d..6c1e696 100644
--- a/msm8998/sdm/libs/hwc2/hwc_callbacks.h
+++ b/msm8998/sdm/libs/hwc2/hwc_callbacks.h
@@ -36,6 +36,8 @@
 #undef HWC2_INCLUDE_STRINGIFICATION
 #undef HWC2_USE_CPP11
 
+#include <mutex>
+
 namespace sdm {
 
 class HWCCallbacks {
@@ -56,6 +58,10 @@
   HWC2_PFN_HOTPLUG hotplug_ = nullptr;
   HWC2_PFN_REFRESH refresh_ = nullptr;
   HWC2_PFN_VSYNC vsync_ = nullptr;
+
+  std::mutex hotplug_mutex_;
+  std::mutex refresh_mutex_;
+  std::mutex vsync_mutex_;
 };
 
 }  // namespace sdm
diff --git a/msm8998/sdm/libs/hwc2/hwc_display.cpp b/msm8998/sdm/libs/hwc2/hwc_display.cpp
index 498c05d..46abc14 100644
--- a/msm8998/sdm/libs/hwc2/hwc_display.cpp
+++ b/msm8998/sdm/libs/hwc2/hwc_display.cpp
@@ -545,8 +545,8 @@
       layer_buffer->release_fence_fd = -1;
       layer->src_rect.left = 0;
       layer->src_rect.top = 0;
-      layer->src_rect.right = layer_buffer->width;
-      layer->src_rect.bottom = layer_buffer->height;
+      layer->src_rect.right = FLOAT(layer_buffer->width);
+      layer->src_rect.bottom = FLOAT(layer_buffer->height);
     }
 
     if (layer->frame_rate > metadata_refresh_rate_) {
@@ -1715,8 +1715,8 @@
 
     LayerRect rect;
     rect.top = 0; rect.left = 0;
-    rect.right = primary_width;
-    rect.bottom = primary_height;
+    rect.right = FLOAT(primary_width);
+    rect.bottom = FLOAT(primary_height);
 
     solid_fill_layer_->composition = kCompositionGPU;
     solid_fill_layer_->src_rect = rect;
diff --git a/msm8998/sdm/libs/hwc2/hwc_display_external.cpp b/msm8998/sdm/libs/hwc2/hwc_display_external.cpp
index f4878c8..14a5dd8 100644
--- a/msm8998/sdm/libs/hwc2/hwc_display_external.cpp
+++ b/msm8998/sdm/libs/hwc2/hwc_display_external.cpp
@@ -154,8 +154,8 @@
     return;
   }
 
-  uint32_t new_mixer_width = UINT32(mixer_width * FLOAT(1.0f - width_ratio));
-  uint32_t new_mixer_height = UINT32(mixer_height * FLOAT(1.0f - height_ratio));
+  uint32_t new_mixer_width = UINT32(FLOAT(mixer_width) * (1.0f - width_ratio));
+  uint32_t new_mixer_height = UINT32(FLOAT(mixer_height) * (1.0f - height_ratio));
 
   int x_offset = INT((FLOAT(mixer_width) * width_ratio) / 2.0f);
   int y_offset = INT((FLOAT(mixer_height) * height_ratio) / 2.0f);
diff --git a/msm8998/sdm/libs/hwc2/hwc_layers.cpp b/msm8998/sdm/libs/hwc2/hwc_layers.cpp
index ea8841b..ee145f5 100644
--- a/msm8998/sdm/libs/hwc2/hwc_layers.cpp
+++ b/msm8998/sdm/libs/hwc2/hwc_layers.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, 2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2017, 2019-2020, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright 2015 The Android Open Source Project
@@ -592,6 +592,7 @@
       format = kFormatYCrCb420PlanarStride16;
       break;
     case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+    case HAL_PIXEL_FORMAT_NV21_ZSL:
       format = kFormatYCrCb420SemiPlanar;
       break;
     case HAL_PIXEL_FORMAT_YCbCr_420_SP:
@@ -679,7 +680,7 @@
   uint32_t fps = 0;
   uint32_t frame_rate = layer->frame_rate;
   if (getMetaData(handle, GET_REFRESH_RATE, &fps) == 0) {
-    frame_rate = RoundToStandardFPS(fps);
+    frame_rate = RoundToStandardFPS(FLOAT(fps));
   }
 
   int32_t interlaced = 0;
diff --git a/msm8998/sdm/libs/hwc2/hwc_session.cpp b/msm8998/sdm/libs/hwc2/hwc_session.cpp
index f077667..1331686 100644
--- a/msm8998/sdm/libs/hwc2/hwc_session.cpp
+++ b/msm8998/sdm/libs/hwc2/hwc_session.cpp
@@ -437,7 +437,7 @@
   }
   auto desc = static_cast<HWC2::Callback>(descriptor);
   auto error = hwc_session->callbacks_.Register(desc, callback_data, pointer);
-  DLOGD("Registering callback: %s", to_string(desc).c_str());
+  DLOGD("%s callback: %s", pointer ? "Registering" : "Deregistering", to_string(desc).c_str());
   if (descriptor == HWC2_CALLBACK_HOTPLUG)
     hwc_session->callbacks_.Hotplug(HWC_DISPLAY_PRIMARY, HWC2::Connection::Connected);
   return INT32(error);