refactor HWComposer to break dependency with the HAL headers

HWComposer must abstract the HWC HAL entirely, so that the
HAL can continue to evolve (and break binary compatibility)
without breaking SurfaceFlinger. The HWC data structure had
leaked outside of HWComposer, this is now fixed.

We now have an abstract interface that provide all the
needed functionality, HWCompose provides concrete
implementations of it based on the the HWC version.

Change-Id: I40c4676dc986b682ede5520a1c60efe64037b0bb
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 61b5f71..e2c7aed 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -800,12 +800,13 @@
         const Vector< sp<LayerBase> >& currentLayers(mVisibleLayersSortedByZ);
         const size_t count = currentLayers.size();
         hwc.createWorkList(count);
-        hwc_layer_t* const cur(hwc.getLayers());
-        for (size_t i=0 ; cur && i<count ; i++) {
-            currentLayers[i]->setGeometry(&cur[i]);
+
+        HWComposer::LayerListIterator cur = hwc.begin();
+        const HWComposer::LayerListIterator end = hwc.end();
+        for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
+            currentLayers[i]->setGeometry(*cur);
             if (mDebugDisableHWC || mDebugRegion) {
-                cur[i].compositionType = HWC_FRAMEBUFFER;
-                cur[i].flags |= HWC_SKIP_LAYER;
+                cur->setSkip(true);
             }
         }
     }
@@ -859,8 +860,10 @@
 {
     const DisplayHardware& hw(graphicPlane(0).displayHardware());
     HWComposer& hwc(hw.getHwComposer());
-    hwc_layer_t* const cur(hwc.getLayers());
-    if (!cur) {
+
+    HWComposer::LayerListIterator cur = hwc.begin();
+    const HWComposer::LayerListIterator end = hwc.end();
+    if (cur == end) {
         return;
     }
 
@@ -880,9 +883,9 @@
      *  update the per-frame h/w composer data for each layer
      *  and build the transparent region of the FB
      */
-    for (size_t i=0 ; i<count ; i++) {
+    for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
         const sp<LayerBase>& layer(layers[i]);
-        layer->setPerFrameData(&cur[i]);
+        layer->setPerFrameData(*cur);
     }
     status_t err = hwc.prepare();
     ALOGE_IF(err, "HWComposer::prepare failed (%s)", strerror(-err));
@@ -892,10 +895,11 @@
 {
     const DisplayHardware& hw(graphicPlane(0).displayHardware());
     HWComposer& hwc(hw.getHwComposer());
-    hwc_layer_t* const cur(hwc.getLayers());
+    HWComposer::LayerListIterator cur = hwc.begin();
+    const HWComposer::LayerListIterator end = hwc.end();
 
     const size_t fbLayerCount = hwc.getLayerCount(HWC_FRAMEBUFFER);
-    if (!cur || fbLayerCount) {
+    if (cur==end || fbLayerCount) {
         // Never touch the framebuffer if we don't have any framebuffer layers
 
         if (hwc.getLayerCount(HWC_OVERLAY)) {
@@ -920,13 +924,12 @@
 
         const Vector< sp<LayerBase> >& layers(mVisibleLayersSortedByZ);
         const size_t count = layers.size();
-
-        for (size_t i=0 ; i<count ; i++) {
+        for (size_t i=0 ; cur!=end && i<count ; ++i, ++cur) {
             const sp<LayerBase>& layer(layers[i]);
             const Region clip(dirty.intersect(layer->visibleRegionScreen));
             if (!clip.isEmpty()) {
-                if (cur && (cur[i].compositionType == HWC_OVERLAY)) {
-                    if (i && (cur[i].hints & HWC_HINT_CLEAR_FB)
+                if (cur->getCompositionType() == HWC_OVERLAY) {
+                    if (i && (cur->getHints() & HWC_HINT_CLEAR_FB)
                             && layer->isOpaque()) {
                         // never clear the very first layer since we're
                         // guaranteed the FB is already cleared