am f20da889: am ee856671: Merge "opengl Translator: adding type EGLNativeSurfaceType"

* commit 'f20da8890882ee2f313521b07b42f8de1bcebd20':
  opengl Translator: adding type EGLNativeSurfaceType
This commit is contained in:
David Turner
2011-07-06 07:46:36 -07:00
committed by Android Git Automerger
13 changed files with 199 additions and 116 deletions

View File

@@ -515,7 +515,7 @@ EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay display, EGLCon
RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE);
} }
EGLNativePbufferType pb = EglOS::createPbuffer(dpy->nativeType(),cfg,tmpPbSurfacePtr); EGLNativeSurfaceType pb = EglOS::createPbufferSurface(dpy->nativeType(),cfg,tmpPbSurfacePtr);
if(!pb) { if(!pb) {
//TODO: RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_VALUE); dont have bad value //TODO: RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_VALUE); dont have bad value
RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE); RETURN_ERROR(EGL_NO_SURFACE,EGL_BAD_ATTRIBUTE);
@@ -558,7 +558,7 @@ static bool destroySurfaceIfNotCurrent(EglDisplay* dpy,SurfacePtr surface) {
EglContext* currCtx = static_cast<EglContext*>(thread->eglContext); EglContext* currCtx = static_cast<EglContext*>(thread->eglContext);
if((!currCtx) || (currCtx && !currCtx->usingSurface(surface))){ if((!currCtx) || (currCtx && !currCtx->usingSurface(surface))){
if(surface->type() == EglSurface::PBUFFER) { if(surface->type() == EglSurface::PBUFFER) {
EglOS::releasePbuffer(dpy->nativeType(),reinterpret_cast<EGLNativePbufferType>(surface->native())); EglOS::releasePbuffer(dpy->nativeType(),surface->native());
} }
return true; return true;
} }
@@ -727,21 +727,21 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw
} }
EGLNativeDisplayType nativeDisplay = dpy->nativeType(); EGLNativeDisplayType nativeDisplay = dpy->nativeType();
void* nativeRead = newReadPtr->native(); EGLNativeSurfaceType nativeRead = newReadPtr->native();
void* nativeDraw = newDrawPtr->native(); EGLNativeSurfaceType nativeDraw = newDrawPtr->native();
//checking native window validity //checking native window validity
if(newReadPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(nativeRead))) { if(newReadPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,nativeRead)) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW);
} }
if(newDrawPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(nativeDraw))) { if(newDrawPtr->type() == EglSurface::WINDOW && !EglOS::validNativeWin(nativeDisplay,nativeDraw)) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW); RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_WINDOW);
} }
//checking native pixmap validity //checking native pixmap validity
if(newReadPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(nativeRead))) { if(newReadPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,nativeRead)) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP);
} }
if(newDrawPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(nativeDraw))) { if(newDrawPtr->type() == EglSurface::PIXMAP && !EglOS::validNativePixmap(nativeDisplay,nativeDraw)) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP);
} }
if(prevCtx) { if(prevCtx) {
@@ -811,11 +811,11 @@ EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay display, EGLSurface surf
RETURN_ERROR(EGL_TRUE,EGL_SUCCESS); RETURN_ERROR(EGL_TRUE,EGL_SUCCESS);
} }
if(!currentCtx || !currentCtx->usingSurface(Srfc) || !EglOS::validNativeWin(dpy->nativeType(),reinterpret_cast<EGLNativeWindowType>(Srfc.Ptr()->native()))) { if(!currentCtx || !currentCtx->usingSurface(Srfc) || !EglOS::validNativeWin(dpy->nativeType(),Srfc.Ptr()->native())) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
} }
EglOS::swapBuffers(dpy->nativeType(),reinterpret_cast<EGLNativeWindowType>(Srfc->native())); EglOS::swapBuffers(dpy->nativeType(),Srfc->native());
return EGL_TRUE; return EGL_TRUE;
} }
@@ -827,7 +827,7 @@ EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay display, EGLint interva
if(!currCtx->read().Ptr() || !currCtx->draw().Ptr() || currCtx->draw()->type()!=EglSurface::WINDOW) { if(!currCtx->read().Ptr() || !currCtx->draw().Ptr() || currCtx->draw()->type()!=EglSurface::WINDOW) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_CURRENT_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_CURRENT_SURFACE);
} }
EglOS::swapInterval(dpy->nativeType(),reinterpret_cast<EGLNativeWindowType>(currCtx->draw()->native()),interval); EglOS::swapInterval(dpy->nativeType(),currCtx->draw()->native(),interval);
} else { } else {
RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
} }
@@ -902,21 +902,21 @@ EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine) {
EGLNativeDisplayType nativeDisplay = dpy->nativeType(); EGLNativeDisplayType nativeDisplay = dpy->nativeType();
if(read.Ptr()) { if(read.Ptr()) {
if(read->type() == EglSurface::WINDOW && if(read->type() == EglSurface::WINDOW &&
!EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(read->native()))) { !EglOS::validNativeWin(nativeDisplay,read->native())) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
} }
if(read->type() == EglSurface::PIXMAP && if(read->type() == EglSurface::PIXMAP &&
!EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(read->native()))) { !EglOS::validNativePixmap(nativeDisplay,read->native())) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
} }
} }
if(draw.Ptr()) { if(draw.Ptr()) {
if(draw->type() == EglSurface::WINDOW && if(draw->type() == EglSurface::WINDOW &&
!EglOS::validNativeWin(nativeDisplay,reinterpret_cast<EGLNativeWindowType>(draw->native()))) { !EglOS::validNativeWin(nativeDisplay,draw->native())) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
} }
if(draw->type() == EglSurface::PIXMAP && if(draw->type() == EglSurface::PIXMAP &&
!EglOS::validNativePixmap(nativeDisplay,reinterpret_cast<EGLNativePixmapType>(draw->native()))) { !EglOS::validNativePixmap(nativeDisplay,draw->native())) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE); RETURN_ERROR(EGL_FALSE,EGL_BAD_SURFACE);
} }
} }
@@ -990,7 +990,7 @@ EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay display, EGLSurface surf
EGLNativePixmapType target) { EGLNativePixmapType target) {
VALIDATE_DISPLAY(display); VALIDATE_DISPLAY(display);
VALIDATE_SURFACE(surface,srfc); VALIDATE_SURFACE(surface,srfc);
if(!EglOS::validNativePixmap(dpy->nativeType(),target)) { if(!EglOS::validNativePixmap(dpy->nativeType(),NULL)) {
RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP); RETURN_ERROR(EGL_FALSE,EGL_BAD_NATIVE_PIXMAP);
} }

View File

@@ -108,8 +108,12 @@ bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeWindowType win) {
return nsGetWinDims(win,&width,&height); return nsGetWinDims(win,&width,&height);
} }
bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeSurfaceType win) {
return validNativeWin(dpy,(EGLNativeWindowType)win);
}
//no support for pixmap in mac //no support for pixmap in mac
bool validNativePixmap(EGLNativeDisplayType dpy, EGLNativePixmapType pix) { bool validNativePixmap(EGLNativeDisplayType dpy, EGLNativeSurfaceType pix) {
return true; return true;
} }
@@ -131,17 +135,17 @@ bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pi
return false; return false;
} }
EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){ EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
EGLint width,height,hasMipmap,tmp; EGLint width,height,hasMipmap,tmp;
EGLint target,format; EGLint target,format;
srfc->getDim(&width,&height,&tmp); srfc->getDim(&width,&height,&tmp);
srfc->getTexInfo(&format,&target); srfc->getTexInfo(&format,&target);
srfc->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap); srfc->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap);
EGLint maxMipmap = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0; EGLint maxMipmap = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0;
return nsCreatePBuffer(target,format,maxMipmap,width,height); return (EGLNativeSurfaceType)nsCreatePBuffer(target,format,maxMipmap,width,height);
} }
bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb) { bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb) {
nsDestroyPBuffer(pb); nsDestroyPBuffer(pb);
return true; return true;
} }
@@ -188,14 +192,24 @@ bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLN
return true; return true;
} }
void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win) { void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc){
nsSwapBuffers(); nsSwapBuffers();
} }
void waitNative(){} void waitNative(){}
void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval){ void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval){
nsSwapInterval(&interval); nsSwapInterval(&interval);
} }
EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){
return (EGLNativeSurfaceType)wnd;
}
EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){
return (EGLNativeSurfaceType)pix;
}
void destroySurface(EGLNativeSurfaceType srfc){
}
}; };

View File

@@ -34,21 +34,25 @@
namespace EglOS{ namespace EglOS{
void queryConfigs(EGLNativeDisplayType dpy,int renderable_type,ConfigsList& listOut); void queryConfigs(EGLNativeDisplayType dpy,int renderable_type,ConfigsList& listOut);
bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb); bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb);
bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx); bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx);
bool releaseDisplay(EGLNativeDisplayType dpy); bool releaseDisplay(EGLNativeDisplayType dpy);
bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win);
bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win); bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win);
bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativePixmapType pix); bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix);
bool checkWindowPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height); bool checkWindowPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height);
bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height); bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height);
bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType); bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType);
void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win); void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc);
void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval); void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval);
void waitNative(); void waitNative();
EGLNativeDisplayType getDefaultDisplay(); EGLNativeDisplayType getDefaultDisplay();
EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* pb); EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* pb);
EGLNativeContextType createContext(EGLNativeDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext); EGLNativeContextType createContext(EGLNativeDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext);
EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd);
EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix);
void destroySurface(EGLNativeSurfaceType srfc);
#ifdef _WIN32 #ifdef _WIN32
void initPtrToWglFunctions(); void initPtrToWglFunctions();
#endif #endif

View File

@@ -24,11 +24,9 @@ public:
m_texFormat(EGL_NO_TEXTURE), m_texFormat(EGL_NO_TEXTURE),
m_texTarget(EGL_NO_TEXTURE), m_texTarget(EGL_NO_TEXTURE),
m_texMipmap(EGL_FALSE), m_texMipmap(EGL_FALSE),
m_largest(EGL_FALSE), m_largest(EGL_FALSE){};
m_nativePbuffer(0){};
void* native(){ return (void*)m_nativePbuffer;}; void setNativePbuffer(EGLNativeSurfaceType srfc){ m_native = srfc;};
void setNativePbuffer(EGLNativePbufferType pb){ m_nativePbuffer = pb;};
bool setAttrib(EGLint attrib,EGLint val); bool setAttrib(EGLint attrib,EGLint val);
bool getAttrib(EGLint attrib,EGLint* val); bool getAttrib(EGLint attrib,EGLint* val);
void getDim(EGLint* width,EGLint* height,EGLint* largest){ void getDim(EGLint* width,EGLint* height,EGLint* largest){
@@ -44,6 +42,5 @@ private:
EGLint m_texTarget; EGLint m_texTarget;
EGLint m_texMipmap; EGLint m_texMipmap;
EGLint m_largest; EGLint m_largest;
EGLNativePbufferType m_nativePbuffer;
}; };
#endif #endif

View File

@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "EglPixmapSurface.h" #include "EglPixmapSurface.h"
#include "EglOsApi.h"
std::set<EGLNativePixmapType> EglPixmapSurface::s_associatedPixmaps; std::set<EGLNativePixmapType> EglPixmapSurface::s_associatedPixmaps;
@@ -24,6 +25,7 @@ bool EglPixmapSurface::alreadyAssociatedWithConfig(EGLNativePixmapType pix) {
EglPixmapSurface::EglPixmapSurface(EGLNativePixmapType pix,EglConfig* config):EglSurface(PIXMAP,config,0,0),m_pixmap(pix) { EglPixmapSurface::EglPixmapSurface(EGLNativePixmapType pix,EglConfig* config):EglSurface(PIXMAP,config,0,0),m_pixmap(pix) {
s_associatedPixmaps.insert(pix); s_associatedPixmaps.insert(pix);
m_native = EglOS::createPixmapSurface(pix);
} }
EglPixmapSurface::~EglPixmapSurface() { EglPixmapSurface::~EglPixmapSurface() {

View File

@@ -25,7 +25,6 @@ public:
EglPixmapSurface(EGLNativePixmapType pix,EglConfig* config); EglPixmapSurface(EGLNativePixmapType pix,EglConfig* config);
~EglPixmapSurface(); ~EglPixmapSurface();
void* native(){ return (void*)m_pixmap;};
bool getAttrib(EGLint attrib,EGLint* val); bool getAttrib(EGLint attrib,EGLint* val);
static bool alreadyAssociatedWithConfig(EGLNativePixmapType pix); static bool alreadyAssociatedWithConfig(EGLNativePixmapType pix);

View File

@@ -14,9 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
#include "EglSurface.h" #include "EglSurface.h"
#include "EglOsApi.h"
unsigned int EglSurface::s_nextSurfaceHndl = 0; unsigned int EglSurface::s_nextSurfaceHndl = 0;
EglSurface::~EglSurface(){
if(m_native) EglOS::destroySurface(m_native);
}
bool EglSurface::setAttrib(EGLint attrib,EGLint val) { bool EglSurface::setAttrib(EGLint attrib,EGLint val) {
switch(attrib) { switch(attrib) {
case EGL_WIDTH: case EGL_WIDTH:

View File

@@ -17,9 +17,9 @@
#define EGL_SURFACE_H #define EGL_SURFACE_H
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglinternalplatform.h>
#include <map> #include <map>
#include <GLcommon/SmartPtr.h> #include <GLcommon/SmartPtr.h>
#include "EglConfig.h" #include "EglConfig.h"
class EglSurface; class EglSurface;
@@ -34,7 +34,7 @@ public:
PIXMAP = 3 PIXMAP = 3
} ESurfaceType; } ESurfaceType;
ESurfaceType type(){ return m_type;}; ESurfaceType type(){ return m_type;};
virtual void* native() = 0; EGLNativeSurfaceType native(){return m_native;}
virtual bool setAttrib(EGLint attrib,EGLint val); virtual bool setAttrib(EGLint attrib,EGLint val);
virtual bool getAttrib(EGLint attrib,EGLint* val) = 0; virtual bool getAttrib(EGLint attrib,EGLint* val) = 0;
void setDim(int width,int height){ m_width = width; m_height = height;}; void setDim(int width,int height){ m_width = width; m_height = height;};
@@ -42,7 +42,7 @@ public:
bool destroy(){return m_destroy;}; bool destroy(){return m_destroy;};
EglConfig* getConfig(){return m_config;}; EglConfig* getConfig(){return m_config;};
unsigned int getHndl(){return m_hndl;}; unsigned int getHndl(){return m_hndl;};
virtual ~EglSurface(){}; virtual ~EglSurface();
private: private:
static unsigned int s_nextSurfaceHndl; static unsigned int s_nextSurfaceHndl;
@@ -55,9 +55,11 @@ protected:
m_destroy(false), m_destroy(false),
m_config(config), m_config(config),
m_width(width), m_width(width),
m_height(height){ m_hndl = ++s_nextSurfaceHndl;}; m_height(height),
m_native(NULL){ m_hndl = ++s_nextSurfaceHndl;};
EglConfig* m_config; EglConfig* m_config;
EGLint m_width; EGLint m_width;
EGLint m_height; EGLint m_height;
EGLNativeSurfaceType m_native;
}; };
#endif #endif

View File

@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "EglWindowSurface.h" #include "EglWindowSurface.h"
#include "EglOsApi.h"
std::set<EGLNativeWindowType> EglWindowSurface::s_associatedWins; std::set<EGLNativeWindowType> EglWindowSurface::s_associatedWins;
@@ -24,6 +25,7 @@ bool EglWindowSurface::alreadyAssociatedWithConfig(EGLNativeWindowType win) {
EglWindowSurface::EglWindowSurface(EGLNativeWindowType win,EglConfig* config,unsigned int width,unsigned int height):EglSurface(WINDOW,config,width,height),m_win(win){ EglWindowSurface::EglWindowSurface(EGLNativeWindowType win,EglConfig* config,unsigned int width,unsigned int height):EglSurface(WINDOW,config,width,height),m_win(win){
s_associatedWins.insert(win); s_associatedWins.insert(win);
m_native = EglOS::createWindowSurface(win);
} }
EglWindowSurface:: ~EglWindowSurface() { EglWindowSurface:: ~EglWindowSurface() {

View File

@@ -26,7 +26,6 @@ public:
EglWindowSurface(EGLNativeWindowType win,EglConfig* config,unsigned width,unsigned int height); EglWindowSurface(EGLNativeWindowType win,EglConfig* config,unsigned width,unsigned int height);
~EglWindowSurface(); ~EglWindowSurface();
bool getAttrib(EGLint attrib,EGLint* val); bool getAttrib(EGLint attrib,EGLint* val);
void* native(){ return (void *)m_win;};
static bool alreadyAssociatedWithConfig(EGLNativeWindowType win); static bool alreadyAssociatedWithConfig(EGLNativeWindowType win);
private: private:

View File

@@ -22,8 +22,6 @@
if(a != true) return false; if(a != true) return false;
struct DisplayInfo{ struct DisplayInfo{
DisplayInfo():dc(NULL),hwnd(NULL),isPixelFormatSet(false){}; DisplayInfo():dc(NULL),hwnd(NULL),isPixelFormatSet(false){};
DisplayInfo(HDC hdc,HWND wnd):isPixelFormatSet(false){dc = hdc; hwnd = wnd;}; DisplayInfo(HDC hdc,HWND wnd):isPixelFormatSet(false){dc = hdc; hwnd = wnd;};
@@ -66,7 +64,6 @@ void WinDisplay::setCurrent(int configurationIndex,const DisplayInfo& info){
m_map[configurationIndex] = info; m_map[configurationIndex] = info;
m_current = configurationIndex; m_current = configurationIndex;
} }
namespace EglOS{
struct WglExtProcs{ struct WglExtProcs{
PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB; PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB;
@@ -81,6 +78,62 @@ struct WglExtProcs{
static WglExtProcs* s_wglExtProcs = NULL; static WglExtProcs* s_wglExtProcs = NULL;
class SrfcInfo{
public:
typedef enum {
WINDOW = 0,
PBUFFER = 1,
PIXMAP = 2
}SurfaceType;
explicit SrfcInfo(HWND wnd);
explicit SrfcInfo(HPBUFFERARB pb);
explicit SrfcInfo(HBITMAP bmap);
HWND getHwnd(){ return m_hwnd;};
HDC getDC(){ return m_hdc;};
HBITMAP getBmap(){ return m_bmap;};
HPBUFFERARB getPbuffer(){ return m_pb;};
~SrfcInfo();
private:
HWND m_hwnd;
HPBUFFERARB m_pb;
HBITMAP m_bmap;
HDC m_hdc;
SurfaceType m_type;
};
SrfcInfo::SrfcInfo(HBITMAP bmap):m_hwnd(NULL),
m_pb(NULL),
m_hdc(NULL),
m_type(PIXMAP){
m_bmap = bmap;
}
SrfcInfo::SrfcInfo(HWND wnd):m_pb(NULL),
m_bmap(NULL),
m_type(WINDOW){
m_hwnd = wnd;
m_hdc = GetDC(wnd);
}
SrfcInfo::SrfcInfo(HPBUFFERARB pb):m_hwnd(NULL),
m_bmap(NULL),
m_type(PBUFFER){
m_pb = pb;
if(s_wglExtProcs->wglGetPbufferDCARB){
m_hdc = s_wglExtProcs->wglGetPbufferDCARB(pb);
}
}
SrfcInfo::~SrfcInfo(){
if(m_type == WINDOW){
ReleaseDC(m_hwnd,m_hdc);
}
}
namespace EglOS{
PROC wglGetExtentionsProcAddress(HDC hdc,const char *extension_name,const char* proc_name) PROC wglGetExtentionsProcAddress(HDC hdc,const char *extension_name,const char* proc_name)
{ {
// this is pointer to function which returns pointer to string with list of all wgl extensions // this is pointer to function which returns pointer to string with list of all wgl extensions
@@ -314,14 +367,17 @@ void queryConfigs(EGLNativeDisplayType display,int renderableType,ConfigsList& l
} }
bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win) { bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win) {
return IsWindow(win); return IsWindow(win);
} }
bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativePixmapType pix) { bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win) {
return validNativeWin(dpy,win->getHwnd());
}
bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix) {
BITMAP bm; BITMAP bm;
return GetObject(pix, sizeof(BITMAP), (LPSTR)&bm); return GetObject(pix->getBmap(), sizeof(BITMAP), (LPSTR)&bm);
} }
static bool setPixelFormat(HDC dc,EglConfig* cfg) { static bool setPixelFormat(HDC dc,EglConfig* cfg) {
@@ -382,7 +438,7 @@ bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pi
return true; return true;
} }
EGLNativePbufferType createPbuffer(EGLNativeDisplayType display,EglConfig* cfg,EglPbufferSurface* pbSurface) { EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType display,EglConfig* cfg,EglPbufferSurface* pbSurface) {
//converting configuration into WGL pixel Format //converting configuration into WGL pixel Format
EGLint red,green,blue,alpha,depth,stencil; EGLint red,green,blue,alpha,depth,stencil;
@@ -445,13 +501,13 @@ EGLNativePbufferType createPbuffer(EGLNativeDisplayType display,EglConfig* cfg,E
DWORD err = GetLastError(); DWORD err = GetLastError();
return NULL; return NULL;
} }
return pb; return new SrfcInfo(pb);
} }
bool releasePbuffer(EGLNativeDisplayType display,EGLNativePbufferType pb) { bool releasePbuffer(EGLNativeDisplayType display,EGLNativeSurfaceType pb) {
HDC dis = display->getCurrentDC(); HDC dis = display->getCurrentDC();
if(!s_wglExtProcs->wglReleasePbufferDCARB || !s_wglExtProcs->wglDestroyPbufferARB) return false; if(!s_wglExtProcs->wglReleasePbufferDCARB || !s_wglExtProcs->wglDestroyPbufferARB) return false;
if(!s_wglExtProcs->wglReleasePbufferDCARB(pb,dis) || !s_wglExtProcs->wglDestroyPbufferARB(pb)){ if(!s_wglExtProcs->wglReleasePbufferDCARB(pb->getPbuffer(),pb->getDC()) || !s_wglExtProcs->wglDestroyPbufferARB(pb->getPbuffer())){
DWORD err = GetLastError(); DWORD err = GetLastError();
return false; return false;
} }
@@ -495,39 +551,10 @@ bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx) {
} }
HDC getSurfaceDC(EGLNativeDisplayType dpy,EglSurface* srfc){
switch(srfc->type()){
case EglSurface::WINDOW:
return GetDC(static_cast<EGLNativeWindowType>(srfc->native()));
case EglSurface::PBUFFER:
if(!s_wglExtProcs->wglGetPbufferDCARB) return NULL;
return s_wglExtProcs->wglGetPbufferDCARB(static_cast<EGLNativePbufferType>(srfc->native()));
case EglSurface::PIXMAP: //not supported;
default:
return NULL;
}
}
bool releaseSurfaceDC(EGLNativeDisplayType dpy,HDC dc,EglSurface*srfc){
if(!srfc) return true;
switch(srfc->type()){
case EglSurface::WINDOW:
ReleaseDC(static_cast<EGLNativeWindowType>(srfc->native()),dc);
return true;
case EglSurface::PBUFFER:
if(!s_wglExtProcs->wglReleasePbufferDCARB) return false;
s_wglExtProcs->wglReleasePbufferDCARB(static_cast<EGLNativePbufferType>(srfc->native()),dc);
return true;
case EglSurface::PIXMAP: //not supported;
default:
return false;
}
}
bool makeCurrent(EGLNativeDisplayType display,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx) { bool makeCurrent(EGLNativeDisplayType display,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx) {
HDC hdcRead = read ? getSurfaceDC(display,read):0; HDC hdcRead = read ? read->native()->getDC(): NULL;
HDC hdcDraw = draw ? getSurfaceDC(display,draw):0; HDC hdcDraw = draw ? draw->native()->getDC(): NULL;
bool retVal = false; bool retVal = false;
@@ -535,33 +562,40 @@ bool makeCurrent(EGLNativeDisplayType display,EglSurface* read,EglSurface* draw,
bool ret = wglMakeCurrent(hdcDraw,ctx); bool ret = wglMakeCurrent(hdcDraw,ctx);
return ret; return ret;
} else if (!s_wglExtProcs->wglMakeContextCurrentARB ) { } else if (!s_wglExtProcs->wglMakeContextCurrentARB ) {
printf("OS :1-:make current failed %d\n",GetLastError());
return false; return false;
} }
retVal = s_wglExtProcs->wglMakeContextCurrentARB(hdcDraw,hdcRead,ctx); retVal = s_wglExtProcs->wglMakeContextCurrentARB(hdcDraw,hdcRead,ctx);
printf("OS ::2-make current failed %d\n",GetLastError());
releaseSurfaceDC(display,hdcRead,read);
releaseSurfaceDC(display,hdcDraw,draw);
return retVal; return retVal;
} }
void swapBuffers(EGLNativeDisplayType display,EGLNativeWindowType win) { void swapBuffers(EGLNativeDisplayType display,EGLNativeSurfaceType srfc){
if(!SwapBuffers(srfc->getDC())) {
HDC dc = GetDC(win);
if(!SwapBuffers(dc)) {
DWORD err = GetLastError(); DWORD err = GetLastError();
} }
ReleaseDC(win,dc);
} }
void waitNative(){} void waitNative(){}
void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval) { void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval) {
if (s_wglExtProcs->wglSwapIntervalEXT){ if (s_wglExtProcs->wglSwapIntervalEXT){
s_wglExtProcs->wglSwapIntervalEXT(interval); s_wglExtProcs->wglSwapIntervalEXT(interval);
} }
} }
EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){
return new SrfcInfo(wnd);
}
EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){
return new SrfcInfo(pix);
}
void destroySurface(EGLNativeSurfaceType srfc){
delete srfc;
}
}; };

View File

@@ -34,6 +34,20 @@ static int errorHandlerProc(EGLNativeDisplayType dpy,XErrorEvent* event);
}; };
class SrfcInfo{
public:
typedef enum{
WINDOW = 0,
PBUFFER = 1,
PIXMAP
}SurfaceType;
SrfcInfo(GLXDrawable drawable,SurfaceType type):m_type(type),
m_srfc(drawable){};
GLXDrawable srfc(){return m_srfc;};
private:
SurfaceType m_type;
GLXDrawable m_srfc;
};
int ErrorHandler::s_lastErrorCode = 0; int ErrorHandler::s_lastErrorCode = 0;
android::Mutex ErrorHandler::s_lock; android::Mutex ErrorHandler::s_lock;
@@ -160,12 +174,16 @@ bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeWindowType win) {
return handler.getLastError() == 0; return handler.getLastError() == 0;
} }
bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativePixmapType pix) { bool validNativeWin(EGLNativeDisplayType dpy,EGLNativeSurfaceType win) {
return validNativeWin(dpy,win->srfc());
}
bool validNativePixmap(EGLNativeDisplayType dpy,EGLNativeSurfaceType pix) {
Window root; Window root;
int tmp; int tmp;
unsigned int utmp; unsigned int utmp;
ErrorHandler handler(dpy); ErrorHandler handler(dpy);
if(!XGetGeometry(dpy,pix,&root,&tmp,&tmp,&utmp,&utmp,&utmp,&utmp)) return false; if(!XGetGeometry(dpy,pix->srfc(),&root,&tmp,&tmp,&utmp,&utmp,&utmp,&utmp)) return false;
return handler.getLastError() == 0; return handler.getLastError() == 0;
} }
@@ -194,7 +212,7 @@ bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pi
return depth >= configDepth; return depth >= configDepth;
} }
EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){ EGLNativeSurfaceType createPbufferSurface(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
EGLint width,height,largest; EGLint width,height,largest;
srfc->getDim(&width,&height,&largest); srfc->getDim(&width,&height,&largest);
@@ -204,11 +222,12 @@ EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPb
GLX_LARGEST_PBUFFER ,largest, GLX_LARGEST_PBUFFER ,largest,
None None
}; };
return glXCreatePbuffer(dpy,cfg->nativeConfig(),attribs); GLXPbuffer pb = glXCreatePbuffer(dpy,cfg->nativeConfig(),attribs);
return pb ? new SrfcInfo(pb,SrfcInfo::PBUFFER) : NULL;
} }
bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb) { bool releasePbuffer(EGLNativeDisplayType dis,EGLNativeSurfaceType pb) {
glXDestroyPbuffer(dis,pb); glXDestroyPbuffer(dis,pb->srfc());
return true; return true;
} }
@@ -224,36 +243,29 @@ bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx) {
return true; return true;
} }
GLXDrawable convertSurface(EglSurface* srfc) {
if(!srfc) return None;
switch(srfc->type()){
case EglSurface::PIXMAP:
return (GLXPixmap)srfc->native();
case EglSurface::PBUFFER:
return (GLXPbuffer)srfc->native();
case EglSurface::WINDOW:
default:
return (GLXWindow)srfc->native();
}
}
bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx){ bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx){
ErrorHandler handler(dpy); ErrorHandler handler(dpy);
bool retval = glXMakeContextCurrent(dpy,convertSurface(draw),convertSurface(read),ctx); bool retval = false;
if (!ctx && !read && !draw) {
// unbind
retval = glXMakeContextCurrent(dpy, NULL, NULL, NULL);
}
else if (ctx && read && draw) {
retval = glXMakeContextCurrent(dpy,draw->native()->srfc(),read->native()->srfc(),ctx);
}
return (handler.getLastError() == 0) && retval; return (handler.getLastError() == 0) && retval;
} }
void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win) { void swapBuffers(EGLNativeDisplayType dpy,EGLNativeSurfaceType srfc){
glXSwapBuffers(dpy,win); glXSwapBuffers(dpy,srfc->srfc());
} }
void waitNative() { void waitNative() {
glXWaitX(); glXWaitX();
} }
void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval){ void swapInterval(EGLNativeDisplayType dpy,EGLNativeSurfaceType win,int interval){
const char* extensions = glXQueryExtensionsString(dpy,DefaultScreen(dpy)); const char* extensions = glXQueryExtensionsString(dpy,DefaultScreen(dpy));
typedef void (*GLXSWAPINTERVALEXT)(Display*,GLXDrawable,int); typedef void (*GLXSWAPINTERVALEXT)(Display*,GLXDrawable,int);
GLXSWAPINTERVALEXT glXSwapIntervalEXT = NULL; GLXSWAPINTERVALEXT glXSwapIntervalEXT = NULL;
@@ -262,8 +274,17 @@ void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval)
glXSwapIntervalEXT = (GLXSWAPINTERVALEXT)glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT"); glXSwapIntervalEXT = (GLXSWAPINTERVALEXT)glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT");
} }
if(glXSwapIntervalEXT) { if(glXSwapIntervalEXT) {
glXSwapIntervalEXT(dpy,win,interval); glXSwapIntervalEXT(dpy,win->srfc(),interval);
} }
} }
EGLNativeSurfaceType createWindowSurface(EGLNativeWindowType wnd){
return new SrfcInfo(wnd,SrfcInfo::WINDOW);
}
EGLNativeSurfaceType createPixmapSurface(EGLNativePixmapType pix){
return new SrfcInfo(pix,SrfcInfo::PIXMAP);
}
void destroySurface(EGLNativeSurfaceType srfc){};
}; };

View File

@@ -17,6 +17,10 @@
* limitations under the License. * limitations under the License.
*/ */
class SrfcInfo; //defined in Egl{$platform}Api.cpp
typedef SrfcInfo* SURFACE;
typedef SURFACE EGLNativeSurfaceType;
#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ #if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1