Merge "emulator opengl: pool of fixups to the host side."

This commit is contained in:
David Turner
2011-06-21 11:02:46 -07:00
committed by Android Code Review
16 changed files with 170 additions and 18 deletions

View File

@@ -92,6 +92,17 @@ void ColorBuffer::update(GLenum p_format, GLenum p_type, void *pixels)
fb->unbind_locked(); fb->unbind_locked();
} }
void ColorBuffer::subUpdate(int x, int y, int width, int height, GLenum p_format, GLenum p_type, void *pixels)
{
FrameBuffer *fb = FrameBuffer::getFB();
if (!fb->bind_locked()) return;
s_gl.glBindTexture(GL_TEXTURE_2D, m_tex);
s_gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
s_gl.glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
width, height, p_format, p_type, pixels);
fb->unbind_locked();
}
bool ColorBuffer::blitFromPbuffer(EGLSurface p_pbufSurface) bool ColorBuffer::blitFromPbuffer(EGLSurface p_pbufSurface)
{ {
FrameBuffer *fb = FrameBuffer::getFB(); FrameBuffer *fb = FrameBuffer::getFB();

View File

@@ -33,6 +33,7 @@ public:
GLuint getHeight() const { return m_height; } GLuint getHeight() const { return m_height; }
void update(GLenum p_format, GLenum p_type, void *pixels); void update(GLenum p_format, GLenum p_type, void *pixels);
void subUpdate(int x, int y, int width, int height, GLenum p_format, GLenum p_type, void *pixels);
bool blitFromPbuffer(EGLSurface p_pbufSurface); bool blitFromPbuffer(EGLSurface p_pbufSurface);
bool post(); bool post();
bool bindToTexture(); bool bindToTexture();

View File

@@ -27,6 +27,7 @@ bool init_egl_dispatch()
osUtils::dynLibrary *lib = osUtils::dynLibrary::open(libName); osUtils::dynLibrary *lib = osUtils::dynLibrary::open(libName);
if (!lib) { if (!lib) {
printf("Failed to open %s\n", libName);
return NULL; return NULL;
} }

View File

@@ -196,7 +196,7 @@ void FBConfig::packConfigsInfo(GLuint *buffer)
memcpy(buffer, s_configAttribs, s_numConfigAttribs * sizeof(GLuint)); memcpy(buffer, s_configAttribs, s_numConfigAttribs * sizeof(GLuint));
for (int i=0; i<s_numConfigs; i++) { for (int i=0; i<s_numConfigs; i++) {
memcpy(buffer+(i+1)*s_numConfigAttribs, memcpy(buffer+(i+1)*s_numConfigAttribs,
&s_fbConfigs[i]->m_attribValues, s_fbConfigs[i]->m_attribValues,
s_numConfigAttribs * sizeof(GLuint)); s_numConfigAttribs * sizeof(GLuint));
} }
} }
@@ -222,7 +222,47 @@ int FBConfig::chooseConfig(FrameBuffer *fb, EGLint * attribs, uint32_t * configs
// Query the max matching configs in the backend // Query the max matching configs in the backend
// //
EGLConfig *matchedConfigs = new EGLConfig[nConfigs]; EGLConfig *matchedConfigs = new EGLConfig[nConfigs];
s_egl.eglChooseConfig(dpy, attribs, matchedConfigs, nConfigs, &nConfigs);
//
//Until we have EGLImage implementation, we force pbuf configs
//
bool needToAddPbufAttr = true;
int attribCnt = 0;
EGLint * attrib_p = attribs;
if (attribs) {
while (attrib_p[0] != EGL_NONE) {
if (attrib_p[0] == EGL_SURFACE_TYPE) {
attrib_p[1] = EGL_PBUFFER_BIT; //replace whatever was there before
needToAddPbufAttr = false;
}
attrib_p += 2;
attribCnt += 2;
}
}
EGLint * newAttribs = new EGLint[attribCnt + 1 + ((needToAddPbufAttr) ? 2 : 0)];
attrib_p = newAttribs;
if (needToAddPbufAttr) {
*(attrib_p++) = EGL_SURFACE_TYPE;
*(attrib_p++) = EGL_PBUFFER_BIT;
}
memcpy(attrib_p, attribs, attribCnt*sizeof(EGLint));
attrib_p += attribCnt;
*attrib_p = EGL_NONE;
#if 1
DBG("EGLint %d", sizeof(EGLint));
if (newAttribs) {
EGLint * attrib_p = newAttribs;
while (attrib_p[0] != EGL_NONE) {
DBG("attr: 0x%x %d", attrib_p[0], attrib_p[1]);
attrib_p += 2;
}
}
#endif
s_egl.eglChooseConfig(dpy, newAttribs, matchedConfigs, nConfigs, &nConfigs);
delete newAttribs;
// //
// From all matchedConfigs we need only config_size FBConfigs, so we intersect both lists compating the CONFIG_ID attribute // From all matchedConfigs we need only config_size FBConfigs, so we intersect both lists compating the CONFIG_ID attribute

View File

@@ -106,7 +106,7 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
// //
if (!init_gl_dispatch()) { if (!init_gl_dispatch()) {
// Failed to load GLES // Failed to load GLES
printf("Failed to init_gl_dispatch\n"); ERR("Failed to init_gl_dispatch\n");
return false; return false;
} }
@@ -115,7 +115,7 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
// //
FrameBuffer *fb = new FrameBuffer(p_x, p_y, p_width, p_height); FrameBuffer *fb = new FrameBuffer(p_x, p_y, p_width, p_height);
if (!fb) { if (!fb) {
printf("Fialed to create fb\n"); ERR("Failed to create fb\n");
return false; return false;
} }
@@ -138,11 +138,18 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
// //
fb->m_eglDisplay = s_egl.eglGetDisplay(EGL_DEFAULT_DISPLAY); fb->m_eglDisplay = s_egl.eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (fb->m_eglDisplay == EGL_NO_DISPLAY) { if (fb->m_eglDisplay == EGL_NO_DISPLAY) {
printf("Failed to Initialize backend EGL display\n"); ERR("Failed to Initialize backend EGL display\n");
delete fb; delete fb;
return false; return false;
} }
s_egl.eglInitialize(fb->m_eglDisplay, &fb->m_caps.eglMajor, &fb->m_caps.eglMinor);
if (!s_egl.eglInitialize(fb->m_eglDisplay, &fb->m_caps.eglMajor, &fb->m_caps.eglMinor)) {
ERR("Failed to eglInitialize\n");
delete fb;
return false;
}
DBG("egl: %d %d\n", fb->m_caps.eglMajor, fb->m_caps.eglMinor);
s_egl.eglBindAPI(EGL_OPENGL_ES_API); s_egl.eglBindAPI(EGL_OPENGL_ES_API);
fb->m_nativeWindow = p_window; fb->m_nativeWindow = p_window;
@@ -166,17 +173,26 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
// Create EGL context and Surface attached to the native window, for // Create EGL context and Surface attached to the native window, for
// framebuffer post rendering. // framebuffer post rendering.
// //
#if 0
GLint configAttribs[] = { GLint configAttribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
EGL_NONE EGL_NONE
}; };
#else
GLint configAttribs[] = {
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE
};
#endif
EGLConfig eglConfig; EGLConfig eglConfig;
int n; int n;
if (!s_egl.eglChooseConfig(fb->m_eglDisplay, configAttribs, if (!s_egl.eglChooseConfig(fb->m_eglDisplay, configAttribs,
&eglConfig, 1, &n)) { &eglConfig, 1, &n)) {
printf("Failed on eglChooseConfig\n"); ERR("Failed on eglChooseConfig\n");
delete fb; delete fb;
return false; return false;
} }
@@ -186,6 +202,7 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
(EGLNativeWindowType)p_window, (EGLNativeWindowType)p_window,
NULL); NULL);
if (fb->m_eglSurface == EGL_NO_SURFACE) { if (fb->m_eglSurface == EGL_NO_SURFACE) {
ERR("Failed to create surface\n");
delete fb; delete fb;
return false; return false;
} }
@@ -207,6 +224,7 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
// Make the context current // Make the context current
if (!fb->bind_locked()) { if (!fb->bind_locked()) {
ERR("Failed to make current\n");
delete fb; delete fb;
return false; return false;
} }
@@ -243,6 +261,7 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window,
// //
InitConfigStatus configStatus = FBConfig::initConfigList(fb); InitConfigStatus configStatus = FBConfig::initConfigList(fb);
if (configStatus == INIT_CONFIG_FAILED) { if (configStatus == INIT_CONFIG_FAILED) {
ERR("Failed: Initialize set of configs\n");
delete fb; delete fb;
return false; return false;
} }
@@ -403,6 +422,21 @@ void FrameBuffer::DestroyColorBuffer(HandleType p_colorbuffer)
m_colorbuffers.erase(p_colorbuffer); m_colorbuffers.erase(p_colorbuffer);
} }
bool FrameBuffer::flushWindowSurfaceColorBuffer(HandleType p_surface)
{
android::Mutex::Autolock mutex(m_lock);
WindowSurfaceMap::iterator w( m_windows.find(p_surface) );
if (w == m_windows.end()) {
// bad surface handle
return false;
}
(*w).second->flushColorBuffer();
return true;
}
bool FrameBuffer::setWindowSurfaceColorBuffer(HandleType p_surface, bool FrameBuffer::setWindowSurfaceColorBuffer(HandleType p_surface,
HandleType p_colorbuffer) HandleType p_colorbuffer)
{ {
@@ -425,6 +459,23 @@ bool FrameBuffer::setWindowSurfaceColorBuffer(HandleType p_surface,
return true; return true;
} }
bool FrameBuffer::updateColorBuffer(HandleType p_colorbuffer,
int x, int y, int width, int height,
GLenum format, GLenum type, void *pixels)
{
android::Mutex::Autolock mutex(m_lock);
ColorBufferMap::iterator c( m_colorbuffers.find(p_colorbuffer) );
if (c == m_colorbuffers.end()) {
// bad colorbuffer handle
return false;
}
(*c).second->subUpdate(x, y, width, height, format, type, pixels);
return true;
}
bool FrameBuffer::bindColorBufferToTexture(HandleType p_colorbuffer) bool FrameBuffer::bindColorBufferToTexture(HandleType p_colorbuffer)
{ {
android::Mutex::Autolock mutex(m_lock); android::Mutex::Autolock mutex(m_lock);
@@ -513,6 +564,7 @@ bool FrameBuffer::bindContext(HandleType p_context,
tinfo->currContext = ctx; tinfo->currContext = ctx;
tinfo->currDrawSurf = draw; tinfo->currDrawSurf = draw;
tinfo->currReadSurf = read; tinfo->currReadSurf = read;
tinfo->m_glDec.setContextData(&ctx->decoderContextData());
return true; return true;
} }
@@ -528,6 +580,7 @@ bool FrameBuffer::bind_locked()
if (!s_egl.eglMakeCurrent(m_eglDisplay, m_eglSurface, if (!s_egl.eglMakeCurrent(m_eglDisplay, m_eglSurface,
m_eglSurface, m_eglContext)) { m_eglSurface, m_eglContext)) {
ERR("eglMakeCurrent failed\n");
return false; return false;
} }

View File

@@ -67,7 +67,11 @@ public:
bool bindContext(HandleType p_context, HandleType p_drawSurface, HandleType p_readSurface); bool bindContext(HandleType p_context, HandleType p_drawSurface, HandleType p_readSurface);
bool setWindowSurfaceColorBuffer(HandleType p_surface, HandleType p_colorbuffer); bool setWindowSurfaceColorBuffer(HandleType p_surface, HandleType p_colorbuffer);
bool flushWindowSurfaceColorBuffer(HandleType p_surface);
bool bindColorBufferToTexture(HandleType p_colorbuffer); bool bindColorBufferToTexture(HandleType p_colorbuffer);
bool updateColorBuffer(HandleType p_colorbuffer,
int x, int y, int width, int height,
GLenum format, GLenum type, void *pixels);
bool post(HandleType p_colorbuffer); bool post(HandleType p_colorbuffer);

View File

@@ -18,6 +18,7 @@
#include "SmartPtr.h" #include "SmartPtr.h"
#include <EGL/egl.h> #include <EGL/egl.h>
#include "GLDecoderContextData.h"
class RenderContext; class RenderContext;
typedef SmartPtr<RenderContext> RenderContextPtr; typedef SmartPtr<RenderContext> RenderContextPtr;
@@ -33,6 +34,8 @@ public:
EGLContext getEGLContext() const { return m_ctx; } EGLContext getEGLContext() const { return m_ctx; }
bool isGL2() const { return m_isGL2; } bool isGL2() const { return m_isGL2; }
GLDecoderContextData & decoderContextData() { return m_contextData; }
private: private:
RenderContext(); RenderContext();
@@ -40,6 +43,7 @@ private:
EGLContext m_ctx; EGLContext m_ctx;
int m_config; int m_config;
bool m_isGL2; bool m_isGL2;
GLDecoderContextData m_contextData;
}; };
#endif #endif

View File

@@ -189,6 +189,15 @@ static void rcDestroyColorBuffer(uint32_t colorbuffer)
fb->DestroyColorBuffer( colorbuffer ); fb->DestroyColorBuffer( colorbuffer );
} }
static void rcFlushWindowColorBuffer(uint32_t windowSurface)
{
FrameBuffer *fb = FrameBuffer::getFB();
if (!fb) {
return;
}
fb->flushWindowSurfaceColorBuffer(windowSurface);
}
static void rcSetWindowColorBuffer(uint32_t windowSurface, static void rcSetWindowColorBuffer(uint32_t windowSurface,
uint32_t colorBuffer) uint32_t colorBuffer)
{ {
@@ -257,7 +266,12 @@ static void rcUpdateColorBuffer(uint32_t colorBuffer,
GLint width, GLint height, GLint width, GLint height,
GLenum format, GLenum type, void* pixels) GLenum format, GLenum type, void* pixels)
{ {
// XXX: TBD - should be implemented FrameBuffer *fb = FrameBuffer::getFB();
if (!fb) {
return;
}
fb->updateColorBuffer(colorBuffer, x, y, width, height, format, type, pixels);
} }
void initRenderControlContext(renderControl_decoder_context_t *dec) void initRenderControlContext(renderControl_decoder_context_t *dec)
@@ -276,6 +290,7 @@ void initRenderControlContext(renderControl_decoder_context_t *dec)
dec->set_rcCreateColorBuffer(rcCreateColorBuffer); dec->set_rcCreateColorBuffer(rcCreateColorBuffer);
dec->set_rcDestroyColorBuffer(rcDestroyColorBuffer); dec->set_rcDestroyColorBuffer(rcDestroyColorBuffer);
dec->set_rcSetWindowColorBuffer(rcSetWindowColorBuffer); dec->set_rcSetWindowColorBuffer(rcSetWindowColorBuffer);
dec->set_rcFlushWindowColorBuffer(rcFlushWindowColorBuffer);
dec->set_rcMakeCurrent(rcMakeCurrent); dec->set_rcMakeCurrent(rcMakeCurrent);
dec->set_rcFBPost(rcFBPost); dec->set_rcFBPost(rcFBPost);
dec->set_rcFBSetSwapInterval(rcFBSetSwapInterval); dec->set_rcFBSetSwapInterval(rcFBSetSwapInterval);

View File

@@ -32,6 +32,7 @@ RenderServer *RenderServer::create(int port)
server->m_listenSock = new TcpStream(); server->m_listenSock = new TcpStream();
if (server->m_listenSock->listen(port) < 0) { if (server->m_listenSock->listen(port) < 0) {
ERR("RenderServer::create failed to listen on port %d\n", port);
delete server; delete server;
return NULL; return NULL;
} }
@@ -48,6 +49,7 @@ int RenderServer::Main()
break; break;
} }
DBG("\n\n\n\n Got new stream!!!! \n\n\n\n\n");
// check if we have been requested to exit while waiting on accept // check if we have been requested to exit while waiting on accept
if (m_exit) { if (m_exit) {
break; break;

View File

@@ -15,6 +15,7 @@
*/ */
#include "RenderThread.h" #include "RenderThread.h"
#include "RenderControl.h" #include "RenderControl.h"
#include "ThreadInfo.h"
#include "ReadBuffer.h" #include "ReadBuffer.h"
#include "TimeUtils.h" #include "TimeUtils.h"
#include "GLDispatch.h" #include "GLDispatch.h"
@@ -41,10 +42,11 @@ RenderThread *RenderThread::create(IOStream *p_stream)
int RenderThread::Main() int RenderThread::Main()
{ {
RenderThreadInfo * tInfo = getRenderThreadInfo();
// //
// initialize decoders // initialize decoders
// //
m_glDec.initGL( gl_dispatch_get_proc_func, NULL ); tInfo->m_glDec.initGL( gl_dispatch_get_proc_func, NULL );
initRenderControlContext( &m_rcDec ); initRenderControlContext( &m_rcDec );
ReadBuffer readBuf(m_stream, STREAM_BUFFER_SIZE); ReadBuffer readBuf(m_stream, STREAM_BUFFER_SIZE);
@@ -79,7 +81,7 @@ int RenderThread::Main()
// //
// try to process some of the command buffer using the GLES decoder // try to process some of the command buffer using the GLES decoder
// //
size_t last = m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream); size_t last = tInfo->m_glDec.decode(readBuf.buf(), readBuf.validData(), m_stream);
if (last > 0) { if (last > 0) {
progress = true; progress = true;
readBuf.consume(last); readBuf.consume(last);

View File

@@ -32,7 +32,6 @@ private:
private: private:
IOStream *m_stream; IOStream *m_stream;
GLDecoder m_glDec;
renderControl_decoder_context_t m_rcDec; renderControl_decoder_context_t m_rcDec;
}; };

View File

@@ -18,12 +18,14 @@
#include "RenderContext.h" #include "RenderContext.h"
#include "WindowSurface.h" #include "WindowSurface.h"
#include "GLDecoder.h"
struct RenderThreadInfo struct RenderThreadInfo
{ {
RenderContextPtr currContext; RenderContextPtr currContext;
WindowSurfacePtr currDrawSurf; WindowSurfacePtr currDrawSurf;
WindowSurfacePtr currReadSurf; WindowSurfacePtr currReadSurf;
GLDecoder m_glDec;
}; };
RenderThreadInfo *getRenderThreadInfo(); RenderThreadInfo *getRenderThreadInfo();

View File

@@ -123,12 +123,11 @@ WindowSurface *WindowSurface::create(int p_config, int p_width, int p_height)
} }
// //
// setColorBuffer - this function is called when a new color buffer needs to // flushColorBuffer - The function makes sure that the
// be attached to the surface. The function should make sure that the
// previous attached color buffer is updated, if copy or blit should be done // previous attached color buffer is updated, if copy or blit should be done
// in order to update it - it is being done here. // in order to update it - it is being done here.
// //
void WindowSurface::setColorBuffer(ColorBufferPtr p_colorBuffer) void WindowSurface::flushColorBuffer()
{ {
if (m_attachedColorBuffer.Ptr() != NULL) { if (m_attachedColorBuffer.Ptr() != NULL) {
@@ -143,9 +142,18 @@ void WindowSurface::setColorBuffer(ColorBufferPtr p_colorBuffer)
} }
} }
else { else {
//TODO: EGLImage
} }
} }
}
//
// setColorBuffer - this function is called when a new color buffer needs to
// be attached to the surface. The function doesn't make sure that the
// previous attached color buffer is updated, this is done by flushColorBuffer
//
void WindowSurface::setColorBuffer(ColorBufferPtr p_colorBuffer)
{
m_attachedColorBuffer = p_colorBuffer; m_attachedColorBuffer = p_colorBuffer;
} }
@@ -226,5 +234,4 @@ void WindowSurface::copyToColorBuffer()
s_egl.eglMakeCurrent(fb->getDisplay(), prevDrawSurf, s_egl.eglMakeCurrent(fb->getDisplay(), prevDrawSurf,
prevReadSurf, prevContext); prevReadSurf, prevContext);
free(data);
} }

View File

@@ -37,6 +37,7 @@ public:
EGLSurface getEGLSurface() const { return m_eglSurface; } EGLSurface getEGLSurface() const { return m_eglSurface; }
void setColorBuffer(ColorBufferPtr p_colorBuffer); void setColorBuffer(ColorBufferPtr p_colorBuffer);
void flushColorBuffer();
void bind(RenderContextPtr p_ctx, SurfaceBindType p_bindType); void bind(RenderContextPtr p_ctx, SurfaceBindType p_bindType);
private: private:

View File

@@ -19,6 +19,11 @@
#include <stdlib.h> #include <stdlib.h>
#include "FrameBuffer.h" #include "FrameBuffer.h"
#include <sys/types.h>
#include <unistd.h>
#include <codec_defs.h>
static void printUsage(const char *progName) static void printUsage(const char *progName)
{ {
fprintf(stderr, "Usage: %s -windowid <windowid> [options]\n", progName); fprintf(stderr, "Usage: %s -windowid <windowid> [options]\n", progName);
@@ -33,7 +38,7 @@ static void printUsage(const char *progName)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int portNum = 4141; int portNum = CODEC_SERVER_PORT;
int winX = 0; int winX = 0;
int winY = 0; int winY = 0;
int winWidth = 320; int winWidth = 320;
@@ -84,6 +89,9 @@ int main(int argc, char *argv[])
printUsage(argv[0]); printUsage(argv[0]);
} }
printf("renderer pid %d , press any key to continue...\n", getpid());
getchar();
// //
// initialize Framebuffer // initialize Framebuffer
// //
@@ -95,7 +103,7 @@ int main(int argc, char *argv[])
} }
// //
// Create and run a render server listening to the givven port number // Create and run a render server listening to the given port number
// //
RenderServer *server = RenderServer::create(portNum); RenderServer *server = RenderServer::create(portNum);
if (!server) { if (!server) {

View File

@@ -348,6 +348,7 @@ int ApiGen::genEncoderImpl(const std::string &filename)
e->print(fp, true, "_enc", /* classname + "::" */"", "void *self"); e->print(fp, true, "_enc", /* classname + "::" */"", "void *self");
fprintf(fp, "{\n"); fprintf(fp, "{\n");
// fprintf(fp, "\n\tDBG(\">>>> %s\\n\");\n", e->name().c_str());
fprintf(fp, "\n\t%s *ctx = (%s *)self;\n\n", fprintf(fp, "\n\t%s *ctx = (%s *)self;\n\n",
classname.c_str(), classname.c_str(),
classname.c_str()); classname.c_str());
@@ -454,6 +455,7 @@ int ApiGen::genEncoderImpl(const std::string &filename)
} }
} }
} }
//XXX fprintf(fp, "\n\tDBG(\"<<<< %s\\n\");\n", e->name().c_str());
// todo - return value for pointers // todo - return value for pointers
if (e->retval().isPointer()) { if (e->retval().isPointer()) {
fprintf(stderr, "WARNING: %s : return value of pointer is unsupported\n", fprintf(stderr, "WARNING: %s : return value of pointer is unsupported\n",