Permalink
Browse files

tests: first work regarding a working offscreen window rendering impl…

…ementation
  • Loading branch information...
1 parent fad08c0 commit 33b1d293846b74e3fa2a2f30d2959ad1b1ef01b3 @heeen heeen committed with Carsten Munk Oct 22, 2012
View
@@ -14,6 +14,7 @@ m4_define([hybris_lt_revision], [0])
m4_define([hybris_lt_age], [0])
AC_PROG_CC
+AC_PROG_CXX
AM_PROG_CC_C_O
AC_GNU_SOURCE
AC_DISABLE_STATIC
View
@@ -0,0 +1,17 @@
+#ifndef SUPPORT_H_
+#define SUPPORT_H_
+
+#include <stddef.h>
+
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr: the pointer to the member.
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+#endif
View
@@ -1,6 +1,7 @@
bin_PROGRAMS = \
test_egl \
- test_glesv2
+ test_glesv2 \
+ test_offscreen_rendering
test_egl_SOURCES = test_egl.c
test_egl_CFLAGS = \
@@ -17,3 +18,17 @@ test_glesv2_LDADD = \
$(top_builddir)/common/libhybris-common.la \
$(top_builddir)/egl/libEGL.la \
$(top_builddir)/glesv2/libGLESv2.la
+
+test_offscreen_rendering_SOURCES = \
+ test_offscreen_rendering.cpp \
+ fbdev_window.cpp \
+ nativewindowbase.cpp \
+ offscreen_window.cpp
+test_offscreen_rendering_CXXFLAGS = \
+ -I$(top_srcdir)/include
+test_offscreen_rendering_LDADD = \
+ -lm \
+ $(top_builddir)/common/libhybris-common.la \
+ $(top_builddir)/hardware/libhardware.la \
+ $(top_builddir)/egl/libEGL.la \
+ $(top_builddir)/glesv2/libGLESv2.la
View
@@ -0,0 +1,135 @@
+#include "fbdev_window.h"
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <linux/matroxfb.h> // for FBIO_WAITFORVSYNC
+#include <sys/mman.h> //mmap, munmap
+#include <errno.h>
+
+
+FbDevNativeWindow::FbDevNativeWindow()
+{
+ hw_module_t const* pmodule = NULL;
+ hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pmodule);
+ int err = framebuffer_open(pmodule, &m_fbDev);
+ printf("open framebuffer HAL (%s) format %i", strerror(-err), m_fbDev->format);
+
+ err = gralloc_open(pmodule, &m_gralloc);
+ printf("got gralloc %p err:%s\n", m_gralloc, strerror(-err));
+
+ for(unsigned int i = 0; i < FRAMEBUFFER_PARTITIONS; i++) {
+ m_buffers[i] = new FbDevNativeWindowBuffer(width(), height(), m_fbDev->format, GRALLOC_USAGE_HW_FB);
+
+ int err = m_gralloc->alloc(m_gralloc,
+ width(), height(), m_fbDev->format,
+ GRALLOC_USAGE_HW_FB,
+ &m_buffers[i]->handle,
+ &m_buffers[i]->stride);
+ printf("buffer %i is at %p (native %p) err=%s handle=%i stride=%i\n",
+ i, m_buffers[i], (ANativeWindowBuffer*) m_buffers[i],
+ strerror(-err), m_buffers[i]->handle, m_buffers[i]->stride);
+
+
+ }
+ m_frontbuffer = 0;
+ m_tailbuffer = 1;
+
+
+}
+
+FbDevNativeWindow::~FbDevNativeWindow() {
+ printf("%s\n",__PRETTY_FUNCTION__);
+}
+
+// overloads from BaseNativeWindow
+int FbDevNativeWindow::setSwapInterval(int interval) {
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return 0;
+}
+
+int FbDevNativeWindow::dequeueBuffer(BaseNativeWindowBuffer **buffer){
+ printf("%s\n",__PRETTY_FUNCTION__);
+ *buffer = m_buffers[m_tailbuffer];
+ printf("dequeueing buffer %i %p",m_tailbuffer, m_buffers[m_tailbuffer]);
+ m_tailbuffer++;
+ if(m_tailbuffer == FRAMEBUFFER_PARTITIONS)
+ m_tailbuffer = 0;
+ return NO_ERROR;
+}
+
+int FbDevNativeWindow::lockBuffer(BaseNativeWindowBuffer* buffer){
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return NO_ERROR;
+}
+
+int FbDevNativeWindow::queueBuffer(BaseNativeWindowBuffer* buffer){
+ FbDevNativeWindowBuffer* buf = static_cast<FbDevNativeWindowBuffer*>(buffer);
+ m_frontbuffer++;
+ if(m_frontbuffer == FRAMEBUFFER_PARTITIONS)
+ m_frontbuffer = 0;
+ int res = m_fbDev->post(m_fbDev, buffer->handle);
+ printf("%s %s\n",__PRETTY_FUNCTION__,strerror(res));
+ return NO_ERROR;
+}
+
+int FbDevNativeWindow::cancelBuffer(BaseNativeWindowBuffer* buffer){
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return 0;
+}
+
+unsigned int FbDevNativeWindow::width() const {
+ unsigned int val = m_fbDev->width;
+ printf("%s value: %i\n",__PRETTY_FUNCTION__, val);
+ return val;
+}
+
+unsigned int FbDevNativeWindow::height() const {
+ unsigned int val = m_fbDev->height;
+ printf("%s value: %i\n",__PRETTY_FUNCTION__, val);
+ return val;
+}
+
+unsigned int FbDevNativeWindow::format() const {
+ unsigned int val = m_fbDev->format;
+ printf("%s value: %i\n",__PRETTY_FUNCTION__, val);
+ return val;
+}
+
+unsigned int FbDevNativeWindow::defaultWidth() const {
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return m_fbDev->width;
+}
+
+unsigned int FbDevNativeWindow::defaultHeight() const {
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return m_fbDev->height;
+}
+
+unsigned int FbDevNativeWindow::queueLength() const {
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return 0;
+}
+
+unsigned int FbDevNativeWindow::type() const {
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return NATIVE_WINDOW_FRAMEBUFFER;
+}
+
+unsigned int FbDevNativeWindow::transformHint() const {
+ printf("%s\n",__PRETTY_FUNCTION__);
+ return 0;
+}
+
+int FbDevNativeWindow::setUsage(int usage) {
+ printf("%s usage %i\n",__PRETTY_FUNCTION__, usage);
+ return NO_ERROR;
+}
+
+int FbDevNativeWindow::setBuffersFormat(int format) {
+ printf("%s format %i\n",__PRETTY_FUNCTION__, format);
+ return NO_ERROR;
+}
+
+int FbDevNativeWindow::setBuffersDimensions(int width, int height) {
+ printf("%s size %ix%i\n",__PRETTY_FUNCTION__, width, height);
+ return NO_ERROR;
+}
View
@@ -0,0 +1,56 @@
+#ifndef FBDEV_WINDOW_H
+#define FBDEV_WINDOW_H
+#include "nativewindowbase.h"
+#include <linux/fb.h>
+#include <hardware/gralloc.h>
+#define FRAMEBUFFER_PARTITIONS 2
+
+class FbDevNativeWindowBuffer : public BaseNativeWindowBuffer
+{
+ friend class FbDevNativeWindow;
+ protected:
+ FbDevNativeWindowBuffer(unsigned int width,
+ unsigned int height,
+ unsigned int format,
+ unsigned int usage) {
+ // Base members
+ ANativeWindowBuffer::width = width;
+ ANativeWindowBuffer::height = height;
+ ANativeWindowBuffer::format = format;
+ ANativeWindowBuffer::usage = usage;
+ };
+};
+
+class FbDevNativeWindow : public BaseNativeWindow
+{
+public:
+ FbDevNativeWindow();
+ ~FbDevNativeWindow();
+protected:
+ // overloads from BaseNativeWindow
+ virtual int setSwapInterval(int interval);
+ virtual int dequeueBuffer(BaseNativeWindowBuffer **buffer);
+ virtual int lockBuffer(BaseNativeWindowBuffer* buffer);
+ virtual int queueBuffer(BaseNativeWindowBuffer* buffer);
+ virtual int cancelBuffer(BaseNativeWindowBuffer* buffer);
+ virtual unsigned int type() const;
+ virtual unsigned int width() const;
+ virtual unsigned int height() const;
+ virtual unsigned int format() const;
+ virtual unsigned int defaultWidth() const;
+ virtual unsigned int defaultHeight() const;
+ virtual unsigned int queueLength() const;
+ virtual unsigned int transformHint() const;
+ // perform calls
+ virtual int setUsage(int usage);
+ virtual int setBuffersFormat(int format);
+ virtual int setBuffersDimensions(int width, int height);
+private:
+ unsigned int m_frontbuffer;
+ unsigned int m_tailbuffer;
+ FbDevNativeWindowBuffer* m_buffers[FRAMEBUFFER_PARTITIONS];
+ alloc_device_t* m_gralloc;
+ framebuffer_device_t* m_fbDev;
+};
+
+#endif
@@ -0,0 +1,2 @@
+#include "nativewindowbase.h"
+
Oops, something went wrong.

0 comments on commit 33b1d29

Please sign in to comment.