cleanups in preparation of bigger changes

- fix typo drawForSreenshot misspelled
- get rid of DisplayDeviceBase
- removed unused or unneeded code
- always pass a DisplayDevice to Layer methods that are called
  on a per-display basis (to make it clear that this could be
  called more than once per composition).

Change-Id: Id948b7e09fe5c06db0e42d40d6ed75dd095c7f44
diff --git a/services/surfaceflinger/DisplayHardware/DisplayDeviceBase.cpp b/services/surfaceflinger/DisplayHardware/DisplayDeviceBase.cpp
deleted file mode 100644
index e0a4de6..0000000
--- a/services/surfaceflinger/DisplayHardware/DisplayDeviceBase.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include "DisplayHardware/DisplayDeviceBase.h"
-
-// ----------------------------------------------------------------------------
-namespace android {
-
-DisplayDeviceBase::DisplayDeviceBase(uint32_t displayIndex) {
-    mScreenAcquired = true;
-}
-
-DisplayDeviceBase::~DisplayDeviceBase() {
-}
-
-bool DisplayDeviceBase::canDraw() const {
-    return mScreenAcquired;
-}
-
-void DisplayDeviceBase::releaseScreen() const {
-    mScreenAcquired = false;
-}
-
-void DisplayDeviceBase::acquireScreen() const {
-    mScreenAcquired = true;
-}
-
-bool DisplayDeviceBase::isScreenAcquired() const {
-    return mScreenAcquired;
-}
-
-}; // namespace android
diff --git a/services/surfaceflinger/DisplayHardware/DisplayDeviceBase.h b/services/surfaceflinger/DisplayHardware/DisplayDeviceBase.h
deleted file mode 100644
index 9432cf2..0000000
--- a/services/surfaceflinger/DisplayHardware/DisplayDeviceBase.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#ifndef ANDROID_DISPLAY_HARDWARE_BASE_H
-#define ANDROID_DISPLAY_HARDWARE_BASE_H
-
-#include <stdint.h>
-
-namespace android {
-
-class DisplayDeviceBase {
-public:
-    DisplayDeviceBase(uint32_t displayIndex);
-    ~DisplayDeviceBase();
-
-    // console management
-    void releaseScreen() const;
-    void acquireScreen() const;
-    bool isScreenAcquired() const;
-
-    bool canDraw() const;
-
-private:
-    mutable int mScreenAcquired;
-};
-
-}; // namespace android
-
-#endif // ANDROID_DISPLAY_HARDWARE_BASE_H
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index b8506ee..d337805 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -185,6 +185,17 @@
 void HWComposer::vsync(int dpy, int64_t timestamp) {
     ATRACE_INT("VSYNC", ++mVSyncCount&1);
     mEventHandler.onVSyncReceived(dpy, timestamp);
+    Mutex::Autolock _l(mLock);
+    mLastHwVSync = timestamp;
+}
+
+nsecs_t HWComposer::getRefreshTimestamp() const {
+    // this returns the last refresh timestamp.
+    // if the last one is not available, we estimate it based on
+    // the refresh period and whatever closest timestamp we have.
+    Mutex::Autolock _l(mLock);
+    nsecs_t now = systemTime(CLOCK_MONOTONIC);
+    return now - ((now - mLastHwVSync) %  mRefreshPeriod);
 }
 
 void HWComposer::eventControl(int event, int enabled) {
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h
index ca41bd3..872ab98 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -189,6 +189,8 @@
 
     void eventControl(int event, int enabled);
 
+    nsecs_t getRefreshTimestamp() const;
+
     // this class is only used to fake the VSync event on systems that don't
     // have it.
     class VSyncThread : public Thread {
@@ -235,6 +237,10 @@
     size_t                          mVSyncCount;
     sp<VSyncThread>                 mVSyncThread;
     bool                            mDebugForceFakeVSync;
+
+    // protected by mLock
+    mutable Mutex mLock;
+    mutable nsecs_t mLastHwVSync;
 };
 
 // ---------------------------------------------------------------------------