graphics: replace non-const references by pointers

Pointers are preferred for output parameters in graphics code.  While at
it, initialize local variables that are for outputs.

Test: builds and boots
Change-Id: I959706ea92949bc2f993ee9beff0c8b0c3121347
diff --git a/graphics/composer/2.1/default/Hwc.cpp b/graphics/composer/2.1/default/Hwc.cpp
index d14de6f..4efb12b 100644
--- a/graphics/composer/2.1/default/Hwc.cpp
+++ b/graphics/composer/2.1/default/Hwc.cpp
@@ -62,88 +62,89 @@
 }
 
 template<typename T>
-void HwcHal::initDispatch(T& func, hwc2_function_descriptor_t desc)
+void HwcHal::initDispatch(hwc2_function_descriptor_t desc, T* outPfn)
 {
     auto pfn = mDevice->getFunction(mDevice, desc);
     if (!pfn) {
         LOG_ALWAYS_FATAL("failed to get hwcomposer2 function %d", desc);
     }
 
-    func = reinterpret_cast<T>(pfn);
+    *outPfn = reinterpret_cast<T>(pfn);
 }
 
 void HwcHal::initDispatch()
 {
-    initDispatch(mDispatch.acceptDisplayChanges,
-            HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES);
-    initDispatch(mDispatch.createLayer, HWC2_FUNCTION_CREATE_LAYER);
-    initDispatch(mDispatch.createVirtualDisplay,
-            HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY);
-    initDispatch(mDispatch.destroyLayer, HWC2_FUNCTION_DESTROY_LAYER);
-    initDispatch(mDispatch.destroyVirtualDisplay,
-            HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY);
-    initDispatch(mDispatch.dump, HWC2_FUNCTION_DUMP);
-    initDispatch(mDispatch.getActiveConfig, HWC2_FUNCTION_GET_ACTIVE_CONFIG);
-    initDispatch(mDispatch.getChangedCompositionTypes,
-            HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES);
-    initDispatch(mDispatch.getClientTargetSupport,
-            HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT);
-    initDispatch(mDispatch.getColorModes, HWC2_FUNCTION_GET_COLOR_MODES);
-    initDispatch(mDispatch.getDisplayAttribute,
-            HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE);
-    initDispatch(mDispatch.getDisplayConfigs,
-            HWC2_FUNCTION_GET_DISPLAY_CONFIGS);
-    initDispatch(mDispatch.getDisplayName, HWC2_FUNCTION_GET_DISPLAY_NAME);
-    initDispatch(mDispatch.getDisplayRequests,
-            HWC2_FUNCTION_GET_DISPLAY_REQUESTS);
-    initDispatch(mDispatch.getDisplayType, HWC2_FUNCTION_GET_DISPLAY_TYPE);
-    initDispatch(mDispatch.getDozeSupport, HWC2_FUNCTION_GET_DOZE_SUPPORT);
-    initDispatch(mDispatch.getHdrCapabilities,
-            HWC2_FUNCTION_GET_HDR_CAPABILITIES);
-    initDispatch(mDispatch.getMaxVirtualDisplayCount,
-            HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT);
-    initDispatch(mDispatch.getReleaseFences,
-            HWC2_FUNCTION_GET_RELEASE_FENCES);
-    initDispatch(mDispatch.presentDisplay, HWC2_FUNCTION_PRESENT_DISPLAY);
-    initDispatch(mDispatch.registerCallback, HWC2_FUNCTION_REGISTER_CALLBACK);
-    initDispatch(mDispatch.setActiveConfig, HWC2_FUNCTION_SET_ACTIVE_CONFIG);
-    initDispatch(mDispatch.setClientTarget, HWC2_FUNCTION_SET_CLIENT_TARGET);
-    initDispatch(mDispatch.setColorMode, HWC2_FUNCTION_SET_COLOR_MODE);
-    initDispatch(mDispatch.setColorTransform,
-            HWC2_FUNCTION_SET_COLOR_TRANSFORM);
-    initDispatch(mDispatch.setCursorPosition,
-            HWC2_FUNCTION_SET_CURSOR_POSITION);
-    initDispatch(mDispatch.setLayerBlendMode,
-            HWC2_FUNCTION_SET_LAYER_BLEND_MODE);
-    initDispatch(mDispatch.setLayerBuffer, HWC2_FUNCTION_SET_LAYER_BUFFER);
-    initDispatch(mDispatch.setLayerColor, HWC2_FUNCTION_SET_LAYER_COLOR);
-    initDispatch(mDispatch.setLayerCompositionType,
-            HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE);
-    initDispatch(mDispatch.setLayerDataspace,
-            HWC2_FUNCTION_SET_LAYER_DATASPACE);
-    initDispatch(mDispatch.setLayerDisplayFrame,
-            HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME);
-    initDispatch(mDispatch.setLayerPlaneAlpha,
-            HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA);
+    initDispatch(HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES,
+            &mDispatch.acceptDisplayChanges);
+    initDispatch(HWC2_FUNCTION_CREATE_LAYER, &mDispatch.createLayer);
+    initDispatch(HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY,
+            &mDispatch.createVirtualDisplay);
+    initDispatch(HWC2_FUNCTION_DESTROY_LAYER, &mDispatch.destroyLayer);
+    initDispatch(HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY,
+            &mDispatch.destroyVirtualDisplay);
+    initDispatch(HWC2_FUNCTION_DUMP, &mDispatch.dump);
+    initDispatch(HWC2_FUNCTION_GET_ACTIVE_CONFIG, &mDispatch.getActiveConfig);
+    initDispatch(HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES,
+            &mDispatch.getChangedCompositionTypes);
+    initDispatch(HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT,
+            &mDispatch.getClientTargetSupport);
+    initDispatch(HWC2_FUNCTION_GET_COLOR_MODES, &mDispatch.getColorModes);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE,
+            &mDispatch.getDisplayAttribute);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_CONFIGS,
+            &mDispatch.getDisplayConfigs);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_NAME, &mDispatch.getDisplayName);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_REQUESTS,
+            &mDispatch.getDisplayRequests);
+    initDispatch(HWC2_FUNCTION_GET_DISPLAY_TYPE, &mDispatch.getDisplayType);
+    initDispatch(HWC2_FUNCTION_GET_DOZE_SUPPORT, &mDispatch.getDozeSupport);
+    initDispatch(HWC2_FUNCTION_GET_HDR_CAPABILITIES,
+            &mDispatch.getHdrCapabilities);
+    initDispatch(HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT,
+            &mDispatch.getMaxVirtualDisplayCount);
+    initDispatch(HWC2_FUNCTION_GET_RELEASE_FENCES,
+            &mDispatch.getReleaseFences);
+    initDispatch(HWC2_FUNCTION_PRESENT_DISPLAY, &mDispatch.presentDisplay);
+    initDispatch(HWC2_FUNCTION_REGISTER_CALLBACK,
+            &mDispatch.registerCallback);
+    initDispatch(HWC2_FUNCTION_SET_ACTIVE_CONFIG, &mDispatch.setActiveConfig);
+    initDispatch(HWC2_FUNCTION_SET_CLIENT_TARGET, &mDispatch.setClientTarget);
+    initDispatch(HWC2_FUNCTION_SET_COLOR_MODE, &mDispatch.setColorMode);
+    initDispatch(HWC2_FUNCTION_SET_COLOR_TRANSFORM,
+            &mDispatch.setColorTransform);
+    initDispatch(HWC2_FUNCTION_SET_CURSOR_POSITION,
+            &mDispatch.setCursorPosition);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_BLEND_MODE,
+            &mDispatch.setLayerBlendMode);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_BUFFER, &mDispatch.setLayerBuffer);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_COLOR, &mDispatch.setLayerColor);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE,
+            &mDispatch.setLayerCompositionType);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_DATASPACE,
+            &mDispatch.setLayerDataspace);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME,
+            &mDispatch.setLayerDisplayFrame);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA,
+            &mDispatch.setLayerPlaneAlpha);
 
     if (hasCapability(Capability::SIDEBAND_STREAM)) {
-        initDispatch(mDispatch.setLayerSidebandStream,
-                HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM);
+        initDispatch(HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM,
+                &mDispatch.setLayerSidebandStream);
     }
 
-    initDispatch(mDispatch.setLayerSourceCrop,
-            HWC2_FUNCTION_SET_LAYER_SOURCE_CROP);
-    initDispatch(mDispatch.setLayerSurfaceDamage,
-            HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE);
-    initDispatch(mDispatch.setLayerTransform,
-            HWC2_FUNCTION_SET_LAYER_TRANSFORM);
-    initDispatch(mDispatch.setLayerVisibleRegion,
-            HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION);
-    initDispatch(mDispatch.setLayerZOrder, HWC2_FUNCTION_SET_LAYER_Z_ORDER);
-    initDispatch(mDispatch.setOutputBuffer, HWC2_FUNCTION_SET_OUTPUT_BUFFER);
-    initDispatch(mDispatch.setPowerMode, HWC2_FUNCTION_SET_POWER_MODE);
-    initDispatch(mDispatch.setVsyncEnabled, HWC2_FUNCTION_SET_VSYNC_ENABLED);
-    initDispatch(mDispatch.validateDisplay, HWC2_FUNCTION_VALIDATE_DISPLAY);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_SOURCE_CROP,
+            &mDispatch.setLayerSourceCrop);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE,
+            &mDispatch.setLayerSurfaceDamage);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_TRANSFORM,
+            &mDispatch.setLayerTransform);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION,
+            &mDispatch.setLayerVisibleRegion);
+    initDispatch(HWC2_FUNCTION_SET_LAYER_Z_ORDER, &mDispatch.setLayerZOrder);
+    initDispatch(HWC2_FUNCTION_SET_OUTPUT_BUFFER, &mDispatch.setOutputBuffer);
+    initDispatch(HWC2_FUNCTION_SET_POWER_MODE, &mDispatch.setPowerMode);
+    initDispatch(HWC2_FUNCTION_SET_VSYNC_ENABLED, &mDispatch.setVsyncEnabled);
+    initDispatch(HWC2_FUNCTION_VALIDATE_DISPLAY, &mDispatch.validateDisplay);
 }
 
 bool HwcHal::hasCapability(Capability capability) const
@@ -165,7 +166,7 @@
 
 Return<void> HwcHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb)
 {
-    uint32_t len;
+    uint32_t len = 0;
     mDispatch.dump(mDevice, &len, nullptr);
 
     std::vector<char> buf(len + 1);
@@ -270,12 +271,12 @@
 }
 
 Error HwcHal::createVirtualDisplay(uint32_t width, uint32_t height,
-    PixelFormat& format, Display& display)
+    PixelFormat* format, Display* outDisplay)
 {
-    int32_t hwc_format = static_cast<int32_t>(format);
+    int32_t hwc_format = static_cast<int32_t>(*format);
     int32_t err = mDispatch.createVirtualDisplay(mDevice, width, height,
-            &hwc_format, &display);
-    format = static_cast<PixelFormat>(hwc_format);
+            &hwc_format, outDisplay);
+    *format = static_cast<PixelFormat>(hwc_format);
 
     return static_cast<Error>(err);
 }
@@ -286,9 +287,9 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::createLayer(Display display, Layer& layer)
+Error HwcHal::createLayer(Display display, Layer* outLayer)
 {
-    int32_t err = mDispatch.createLayer(mDevice, display, &layer);
+    int32_t err = mDispatch.createLayer(mDevice, display, outLayer);
     return static_cast<Error>(err);
 }
 
@@ -298,9 +299,9 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getActiveConfig(Display display, Config& config)
+Error HwcHal::getActiveConfig(Display display, Config* outConfig)
 {
-    int32_t err = mDispatch.getActiveConfig(mDevice, display, &config);
+    int32_t err = mDispatch.getActiveConfig(mDevice, display, outConfig);
     return static_cast<Error>(err);
 }
 
@@ -314,7 +315,7 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getColorModes(Display display, hidl_vec<ColorMode>& modes)
+Error HwcHal::getColorModes(Display display, hidl_vec<ColorMode>* outModes)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getColorModes(mDevice, display, &count, nullptr);
@@ -322,12 +323,12 @@
         return static_cast<Error>(err);
     }
 
-    modes.resize(count);
+    outModes->resize(count);
     err = mDispatch.getColorModes(mDevice, display, &count,
             reinterpret_cast<std::underlying_type<ColorMode>::type*>(
-                modes.data()));
+                outModes->data()));
     if (err != HWC2_ERROR_NONE) {
-        modes = hidl_vec<ColorMode>();
+        *outModes = hidl_vec<ColorMode>();
         return static_cast<Error>(err);
     }
 
@@ -335,14 +336,14 @@
 }
 
 Error HwcHal::getDisplayAttribute(Display display, Config config,
-        IComposerClient::Attribute attribute, int32_t& value)
+        IComposerClient::Attribute attribute, int32_t* outValue)
 {
     int32_t err = mDispatch.getDisplayAttribute(mDevice, display, config,
-            static_cast<int32_t>(attribute), &value);
+            static_cast<int32_t>(attribute), outValue);
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getDisplayConfigs(Display display, hidl_vec<Config>& configs)
+Error HwcHal::getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getDisplayConfigs(mDevice, display,
@@ -351,18 +352,18 @@
         return static_cast<Error>(err);
     }
 
-    configs.resize(count);
+    outConfigs->resize(count);
     err = mDispatch.getDisplayConfigs(mDevice, display,
-            &count, configs.data());
+            &count, outConfigs->data());
     if (err != HWC2_ERROR_NONE) {
-        configs = hidl_vec<Config>();
+        *outConfigs = hidl_vec<Config>();
         return static_cast<Error>(err);
     }
 
     return Error::NONE;
 }
 
-Error HwcHal::getDisplayName(Display display, hidl_string& name)
+Error HwcHal::getDisplayName(Display display, hidl_string* outName)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getDisplayName(mDevice, display, &count, nullptr);
@@ -378,44 +379,49 @@
     buf.resize(count + 1);
     buf[count] = '\0';
 
-    name = buf.data();
+    *outName = buf.data();
 
     return Error::NONE;
 }
 
-Error HwcHal::getDisplayType(Display display, IComposerClient::DisplayType& type)
+Error HwcHal::getDisplayType(Display display,
+        IComposerClient::DisplayType* outType)
 {
     int32_t hwc_type = HWC2_DISPLAY_TYPE_INVALID;
     int32_t err = mDispatch.getDisplayType(mDevice, display, &hwc_type);
-    type = static_cast<IComposerClient::DisplayType>(hwc_type);
+    *outType = static_cast<IComposerClient::DisplayType>(hwc_type);
 
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getDozeSupport(Display display, bool& support)
+Error HwcHal::getDozeSupport(Display display, bool* outSupport)
 {
     int32_t hwc_support = 0;
     int32_t err = mDispatch.getDozeSupport(mDevice, display, &hwc_support);
-    support = hwc_support;
+    *outSupport = hwc_support;
 
     return static_cast<Error>(err);
 }
 
-Error HwcHal::getHdrCapabilities(Display display, hidl_vec<Hdr>& types,
-        float& maxLuminance, float& maxAverageLuminance, float& minLuminance)
+Error HwcHal::getHdrCapabilities(Display display, hidl_vec<Hdr>* outTypes,
+        float* outMaxLuminance, float* outMaxAverageLuminance,
+        float* outMinLuminance)
 {
     uint32_t count = 0;
     int32_t err = mDispatch.getHdrCapabilities(mDevice, display, &count,
-            nullptr, &maxLuminance, &maxAverageLuminance, &minLuminance);
+            nullptr, outMaxLuminance, outMaxAverageLuminance,
+            outMinLuminance);
     if (err != HWC2_ERROR_NONE) {
         return static_cast<Error>(err);
     }
 
-    types.resize(count);
+    outTypes->resize(count);
     err = mDispatch.getHdrCapabilities(mDevice, display, &count,
-            reinterpret_cast<std::underlying_type<Hdr>::type*>(types.data()),
-            &maxLuminance, &maxAverageLuminance, &minLuminance);
+            reinterpret_cast<std::underlying_type<Hdr>::type*>(
+                outTypes->data()), outMaxLuminance,
+            outMaxAverageLuminance, outMinLuminance);
     if (err != HWC2_ERROR_NONE) {
+        *outTypes = hidl_vec<Hdr>();
         return static_cast<Error>(err);
     }
 
@@ -480,11 +486,11 @@
 }
 
 Error HwcHal::validateDisplay(Display display,
-        std::vector<Layer>& changedLayers,
-        std::vector<IComposerClient::Composition>& compositionTypes,
-        uint32_t& displayRequestMask,
-        std::vector<Layer>& requestedLayers,
-        std::vector<uint32_t>& requestMasks)
+        std::vector<Layer>* outChangedLayers,
+        std::vector<IComposerClient::Composition>* outCompositionTypes,
+        uint32_t* outDisplayRequestMask,
+        std::vector<Layer>* outRequestedLayers,
+        std::vector<uint32_t>* outRequestMasks)
 {
     uint32_t types_count = 0;
     uint32_t reqs_count = 0;
@@ -500,16 +506,16 @@
         return static_cast<Error>(err);
     }
 
-    changedLayers.resize(types_count);
-    compositionTypes.resize(types_count);
+    outChangedLayers->resize(types_count);
+    outCompositionTypes->resize(types_count);
     err = mDispatch.getChangedCompositionTypes(mDevice, display,
-            &types_count, changedLayers.data(),
+            &types_count, outChangedLayers->data(),
             reinterpret_cast<
             std::underlying_type<IComposerClient::Composition>::type*>(
-                compositionTypes.data()));
+                outCompositionTypes->data()));
     if (err != HWC2_ERROR_NONE) {
-        changedLayers.clear();
-        compositionTypes.clear();
+        outChangedLayers->clear();
+        outCompositionTypes->clear();
         return static_cast<Error>(err);
     }
 
@@ -517,26 +523,26 @@
     err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs,
             &reqs_count, nullptr, nullptr);
     if (err != HWC2_ERROR_NONE) {
-        changedLayers.clear();
-        compositionTypes.clear();
+        outChangedLayers->clear();
+        outCompositionTypes->clear();
         return static_cast<Error>(err);
     }
 
-    requestedLayers.resize(reqs_count);
-    requestMasks.resize(reqs_count);
+    outRequestedLayers->resize(reqs_count);
+    outRequestMasks->resize(reqs_count);
     err = mDispatch.getDisplayRequests(mDevice, display, &display_reqs,
-            &reqs_count, requestedLayers.data(),
-            reinterpret_cast<int32_t*>(requestMasks.data()));
+            &reqs_count, outRequestedLayers->data(),
+            reinterpret_cast<int32_t*>(outRequestMasks->data()));
     if (err != HWC2_ERROR_NONE) {
-        changedLayers.clear();
-        compositionTypes.clear();
+        outChangedLayers->clear();
+        outCompositionTypes->clear();
 
-        requestedLayers.clear();
-        requestMasks.clear();
+        outRequestedLayers->clear();
+        outRequestMasks->clear();
         return static_cast<Error>(err);
     }
 
-    displayRequestMask = display_reqs;
+    *outDisplayRequestMask = display_reqs;
 
     return static_cast<Error>(err);
 }
@@ -547,11 +553,11 @@
     return static_cast<Error>(err);
 }
 
-Error HwcHal::presentDisplay(Display display, int32_t& presentFence,
-        std::vector<Layer>& layers, std::vector<int32_t>& releaseFences)
+Error HwcHal::presentDisplay(Display display, int32_t* outPresentFence,
+        std::vector<Layer>* outLayers, std::vector<int32_t>* outReleaseFences)
 {
-    presentFence = -1;
-    int32_t err = mDispatch.presentDisplay(mDevice, display, &presentFence);
+    *outPresentFence = -1;
+    int32_t err = mDispatch.presentDisplay(mDevice, display, outPresentFence);
     if (err != HWC2_ERROR_NONE) {
         return static_cast<Error>(err);
     }
@@ -564,14 +570,14 @@
         return Error::NONE;
     }
 
-    layers.resize(count);
-    releaseFences.resize(count);
+    outLayers->resize(count);
+    outReleaseFences->resize(count);
     err = mDispatch.getReleaseFences(mDevice, display, &count,
-            layers.data(), releaseFences.data());
+            outLayers->data(), outReleaseFences->data());
     if (err != HWC2_ERROR_NONE) {
         ALOGW("failed to get release fences");
-        layers.clear();
-        releaseFences.clear();
+        outLayers->clear();
+        outReleaseFences->clear();
         return Error::NONE;
     }
 
@@ -687,7 +693,7 @@
 
 IComposer* HIDL_FETCH_IComposer(const char*)
 {
-    const hw_module_t* module;
+    const hw_module_t* module = nullptr;
     int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &module);
     if (err) {
         ALOGE("failed to get hwcomposer module");