Add missing methods in host version of Surface

The version of Surface in libhostgraphics was not complete enough to
render on host platforms.

Bug: 322360037
Test: build libhwui on host
Change-Id: I701dba9ed2eb8d7958082df4d27e03ebdd907d8f
diff --git a/libs/hostgraphics/gui/Surface.h b/libs/hostgraphics/gui/Surface.h
index 36d8fba..0d81037 100644
--- a/libs/hostgraphics/gui/Surface.h
+++ b/libs/hostgraphics/gui/Surface.h
@@ -17,18 +17,21 @@
 #ifndef ANDROID_GUI_SURFACE_H
 #define ANDROID_GUI_SURFACE_H
 
-#include <gui/IGraphicBufferProducer.h>
+#include <system/window.h>
 #include <ui/ANativeObjectBase.h>
 #include <utils/RefBase.h>
-#include <system/window.h>
+
+#include "gui/IGraphicBufferProducer.h"
 
 namespace android {
 
 class Surface : public ANativeObjectBase<ANativeWindow, Surface, RefBase> {
 public:
-    explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer,
-                     bool controlledByApp = false) {
+    explicit Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false)
+            : mBufferProducer(bufferProducer) {
         ANativeWindow::perform = hook_perform;
+        ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
+        ANativeWindow::query = hook_query;
     }
     static bool isValid(const sp<Surface>& surface) { return surface != nullptr; }
     void allocateBuffers() {}
@@ -48,7 +51,11 @@
         return 0;
     }
     virtual int unlockAndPost() { return 0; }
-    virtual int query(int what, int* value) const { return 0; }
+    virtual int query(int what, int* value) const { return mBufferProducer->query(what, value); }
+
+    status_t setDequeueTimeout(nsecs_t timeout) { return OK; }
+
+    nsecs_t getLastDequeueStartTime() const { return 0; }
 
     virtual void destroy() {}
 
@@ -57,12 +64,44 @@
 protected:
     virtual ~Surface() {}
 
-    static int hook_perform(ANativeWindow* window, int operation, ...) { return 0; }
+    static int hook_perform(ANativeWindow* window, int operation, ...) {
+        va_list args;
+        va_start(args, operation);
+        Surface* c = getSelf(window);
+        int result = c->perform(operation, args);
+        va_end(args);
+        return result;
+    }
+
+    static int hook_query(const ANativeWindow* window, int what, int* value) {
+        const Surface* c = getSelf(window);
+        return c->query(what, value);
+    }
+
+    static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer,
+                                  int* fenceFd) {
+        Surface* c = getSelf(window);
+        return c->dequeueBuffer(buffer, fenceFd);
+    }
+
+    virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd) {
+        mBufferProducer->requestBuffer(0, &mBuffer);
+        *buffer = mBuffer.get();
+        return OK;
+    }
+    virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd) { return 0; }
+    virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd) { return 0; }
+    virtual int perform(int operation, va_list args) { return 0; }
+    virtual int setSwapInterval(int interval) { return 0; }
+    virtual int setBufferCount(int bufferCount) { return 0; }
 
 private:
     // can't be copied
     Surface& operator=(const Surface& rhs);
     Surface(const Surface& rhs);
+
+    const sp<IGraphicBufferProducer> mBufferProducer;
+    sp<GraphicBuffer> mBuffer;
 };
 
 } // namespace android