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/HostBufferQueue.cpp b/libs/hostgraphics/HostBufferQueue.cpp
index ec30437..b4fd5d9 100644
--- a/libs/hostgraphics/HostBufferQueue.cpp
+++ b/libs/hostgraphics/HostBufferQueue.cpp
@@ -16,12 +16,15 @@
#include <gui/BufferQueue.h>
+#include <system/window.h>
+
namespace android {
class HostBufferQueue : public IGraphicBufferProducer, public IGraphicBufferConsumer {
public:
HostBufferQueue() : mWidth(0), mHeight(0) { }
+// Consumer
virtual status_t setConsumerIsProtected(bool isProtected) { return OK; }
virtual status_t detachBuffer(int slot) { return OK; }
@@ -51,6 +54,28 @@
virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) { return OK; }
virtual status_t setConsumerUsageBits(uint64_t usage) { return OK; }
+
+// Producer
+ virtual int query(int what, int* value) {
+ switch(what) {
+ case NATIVE_WINDOW_WIDTH:
+ *value = mWidth;
+ break;
+ case NATIVE_WINDOW_HEIGHT:
+ *value = mHeight;
+ break;
+ default:
+ *value = 0;
+ break;
+ }
+ return OK;
+ }
+
+ virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) {
+ *buf = mBuffer;
+ return OK;
+ }
+
private:
sp<GraphicBuffer> mBuffer;
uint32_t mWidth;
diff --git a/libs/hostgraphics/gui/IGraphicBufferProducer.h b/libs/hostgraphics/gui/IGraphicBufferProducer.h
index a1efd0b..1447a4f 100644
--- a/libs/hostgraphics/gui/IGraphicBufferProducer.h
+++ b/libs/hostgraphics/gui/IGraphicBufferProducer.h
@@ -31,6 +31,10 @@
// Disconnect any API originally connected from the process calling disconnect.
AllLocal
};
+
+ virtual int query(int what, int* value) = 0;
+
+ virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
};
} // namespace android
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
diff --git a/libs/hostgraphics/ui/GraphicBuffer.h b/libs/hostgraphics/ui/GraphicBuffer.h
index ac88e44..eec9b23 100644
--- a/libs/hostgraphics/ui/GraphicBuffer.h
+++ b/libs/hostgraphics/ui/GraphicBuffer.h
@@ -22,24 +22,27 @@
#include <vector>
+#include <ui/ANativeObjectBase.h>
#include <ui/PixelFormat.h>
#include <ui/Rect.h>
-
#include <utils/RefBase.h>
namespace android {
-class GraphicBuffer : virtual public RefBase {
+class GraphicBuffer : public ANativeObjectBase<ANativeWindowBuffer, GraphicBuffer, RefBase> {
public:
- GraphicBuffer(uint32_t w, uint32_t h):width(w),height(h) {
+ GraphicBuffer(uint32_t w, uint32_t h) {
data.resize(w*h);
+ reserved[0] = data.data();
+ width = w;
+ height = h;
}
uint32_t getWidth() const { return static_cast<uint32_t>(width); }
uint32_t getHeight() const { return static_cast<uint32_t>(height); }
uint32_t getStride() const { return static_cast<uint32_t>(width); }
uint64_t getUsage() const { return 0; }
PixelFormat getPixelFormat() const { return PIXEL_FORMAT_RGBA_8888; }
- //uint32_t getLayerCount() const { return static_cast<uint32_t>(layerCount); }
+
Rect getBounds() const { return Rect(width, height); }
status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect,
@@ -54,8 +57,6 @@
status_t unlockAsync(int *fenceFd) { return OK; }
private:
- uint32_t width;
- uint32_t height;
std::vector<uint32_t> data;
};