Commit 58df2f60 by Nicolas Capens

Store EGL images in a namespace.

This allows validating the EGL image handles. It also ensures that on 64-bit platforms the handles fit in 32-bit so they can be exchanged through 32-bit applications (e.g. on a 32-bit virtual machine). Change-Id: Ie02b00edd2cf7fa02b38316ee7d21c22eae720b5 Reviewed-on: https://swiftshader-review.googlesource.com/5500Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent e7e70d03
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "main.h" #include "main.h"
#include "libEGL/Surface.h" #include "libEGL/Surface.h"
#include "libEGL/Context.hpp" #include "libEGL/Context.hpp"
#include "common/Image.hpp"
#include "common/debug.h" #include "common/debug.h"
#include "Common/MutexLock.hpp" #include "Common/MutexLock.hpp"
...@@ -196,6 +197,11 @@ void Display::terminate() ...@@ -196,6 +197,11 @@ void Display::terminate()
{ {
destroyContext(*mContextSet.begin()); destroyContext(*mContextSet.begin());
} }
while(!mSharedImageNameSpace.empty())
{
destroySharedImage((EGLImageKHR)mSharedImageNameSpace.firstName());
}
} }
bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig) bool Display::getConfigs(EGLConfig *configs, const EGLint *attribList, EGLint configSize, EGLint *numConfig)
...@@ -581,6 +587,33 @@ void *Display::getNativeDisplay() const ...@@ -581,6 +587,33 @@ void *Display::getNativeDisplay() const
return nativeDisplay; return nativeDisplay;
} }
EGLImageKHR Display::createSharedImage(Image *image)
{
return (EGLImageKHR)mSharedImageNameSpace.allocate(image);
}
bool Display::destroySharedImage(EGLImageKHR image)
{
GLuint name = (GLuint)reinterpret_cast<intptr_t>(image);
Image *eglImage = mSharedImageNameSpace.find(name);
if(!eglImage)
{
return false;
}
eglImage->destroyShared();
mSharedImageNameSpace.remove(name);
return true;
}
Image *Display::getSharedImage(EGLImageKHR image)
{
GLuint name = (GLuint)reinterpret_cast<intptr_t>(image);
return mSharedImageNameSpace.find(name);
}
sw::Format Display::getDisplayFormat() const sw::Format Display::getDisplayFormat() const
{ {
#if defined(_WIN32) #if defined(_WIN32)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "Config.h" #include "Config.h"
#include "Sync.hpp" #include "Sync.hpp"
#include "common/NameSpace.hpp"
#include <set> #include <set>
...@@ -28,6 +29,7 @@ namespace egl ...@@ -28,6 +29,7 @@ namespace egl
{ {
class Surface; class Surface;
class Context; class Context;
class Image;
const EGLDisplay PRIMARY_DISPLAY = (EGLDisplay)1; const EGLDisplay PRIMARY_DISPLAY = (EGLDisplay)1;
const EGLDisplay HEADLESS_DISPLAY = (EGLDisplay)0xFACE1E55; const EGLDisplay HEADLESS_DISPLAY = (EGLDisplay)0xFACE1E55;
...@@ -64,7 +66,10 @@ namespace egl ...@@ -64,7 +66,10 @@ namespace egl
EGLint getMaxSwapInterval() const; EGLint getMaxSwapInterval() const;
void *getNativeDisplay() const; void *getNativeDisplay() const;
const char *getExtensionString() const;
EGLImageKHR createSharedImage(Image *image);
bool destroySharedImage(EGLImageKHR);
virtual Image *getSharedImage(EGLImageKHR name);
private: private:
explicit Display(void *nativeDisplay); explicit Display(void *nativeDisplay);
...@@ -87,6 +92,8 @@ namespace egl ...@@ -87,6 +92,8 @@ namespace egl
typedef std::set<FenceSync*> SyncSet; typedef std::set<FenceSync*> SyncSet;
SyncSet mSyncSet; SyncSet mSyncSet;
gl::NameSpace<Image> mSharedImageNameSpace;
}; };
} }
......
...@@ -117,6 +117,7 @@ ...@@ -117,6 +117,7 @@
<Unit filename="../../Common/SharedLibrary.hpp" /> <Unit filename="../../Common/SharedLibrary.hpp" />
<Unit filename="../../Main/libX11.cpp" /> <Unit filename="../../Main/libX11.cpp" />
<Unit filename="../../Main/libX11.hpp" /> <Unit filename="../../Main/libX11.hpp" />
<Unit filename="../common/NameSpace.hpp" />
<Unit filename="../common/Object.cpp" /> <Unit filename="../common/Object.cpp" />
<Unit filename="../common/Object.hpp" /> <Unit filename="../common/Object.hpp" />
<Unit filename="../common/debug.cpp" /> <Unit filename="../common/debug.cpp" />
......
...@@ -982,7 +982,10 @@ EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLCl ...@@ -982,7 +982,10 @@ EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLCl
return error(EGL_BAD_ATTRIBUTE, EGL_NO_IMAGE_KHR); return error(EGL_BAD_ATTRIBUTE, EGL_NO_IMAGE_KHR);
} }
return success(new AndroidNativeImage(nativeBuffer)); Image *image = new AndroidNativeImage(nativeBuffer);
EGLImageKHR eglImage = display->createSharedImage(image);
return success(eglImage);
} }
#endif #endif
...@@ -1000,7 +1003,7 @@ EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLCl ...@@ -1000,7 +1003,7 @@ EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLCl
return error(validationResult, EGL_NO_IMAGE_KHR); return error(validationResult, EGL_NO_IMAGE_KHR);
} }
egl::Image *image = context->createSharedImage(target, name, textureLevel); Image *image = context->createSharedImage(target, name, textureLevel);
if(!image) if(!image)
{ {
...@@ -1012,7 +1015,9 @@ EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLCl ...@@ -1012,7 +1015,9 @@ EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLCl
return error(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); return error(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
} }
return success((EGLImageKHR)image); EGLImageKHR eglImage = display->createSharedImage(image);
return success(eglImage);
} }
EGLBoolean DestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) EGLBoolean DestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
...@@ -1026,14 +1031,11 @@ EGLBoolean DestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) ...@@ -1026,14 +1031,11 @@ EGLBoolean DestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
return error(EGL_BAD_DISPLAY, EGL_FALSE); return error(EGL_BAD_DISPLAY, EGL_FALSE);
} }
if(!image) if(!display->destroySharedImage(image))
{ {
return error(EGL_BAD_PARAMETER, EGL_FALSE); return error(EGL_BAD_PARAMETER, EGL_FALSE);
} }
egl::Image *glImage = static_cast<egl::Image*>(image);
glImage->destroyShared();
return success(EGL_TRUE); return success(EGL_TRUE);
} }
......
...@@ -308,6 +308,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans ...@@ -308,6 +308,7 @@ copy "$(OutDir)libEGL.dll" "$(SolutionDir)lib\$(Configuration)_$(Platform)\trans
<ItemGroup> <ItemGroup>
<ClInclude Include="..\common\debug.h" /> <ClInclude Include="..\common\debug.h" />
<ClInclude Include="..\common\Image.hpp" /> <ClInclude Include="..\common\Image.hpp" />
<ClInclude Include="..\common\NameSpace.hpp" />
<ClInclude Include="..\common\Object.hpp" /> <ClInclude Include="..\common\Object.hpp" />
<ClInclude Include="..\include\EGL\egl.h" /> <ClInclude Include="..\include\EGL\egl.h" />
<ClInclude Include="..\include\EGL\eglext.h" /> <ClInclude Include="..\include\EGL\eglext.h" />
......
...@@ -79,6 +79,9 @@ ...@@ -79,6 +79,9 @@
<ClInclude Include="Sync.hpp"> <ClInclude Include="Sync.hpp">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\common\NameSpace.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="libEGL.rc" /> <ResourceCompile Include="libEGL.rc" />
......
...@@ -3158,7 +3158,12 @@ egl::Image *Context::createSharedImage(EGLenum target, GLuint name, GLuint textu ...@@ -3158,7 +3158,12 @@ egl::Image *Context::createSharedImage(EGLenum target, GLuint name, GLuint textu
} }
else UNREACHABLE(target); else UNREACHABLE(target);
return 0; return nullptr;
}
egl::Image *Context::getSharedImage(GLeglImageOES image)
{
return display->getSharedImage(image);
} }
Device *Context::getDevice() Device *Context::getDevice()
......
...@@ -509,6 +509,7 @@ public: ...@@ -509,6 +509,7 @@ public:
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel); virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel); virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
egl::Image *getSharedImage(GLeglImageOES image);
Device *getDevice(); Device *getDevice();
......
...@@ -614,7 +614,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo ...@@ -614,7 +614,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
renderTarget->release(); renderTarget->release();
} }
void Texture2D::setImage(egl::Image *sharedImage) void Texture2D::setSharedImage(egl::Image *sharedImage)
{ {
sharedImage->addRef(); sharedImage->addRef();
......
...@@ -150,7 +150,7 @@ public: ...@@ -150,7 +150,7 @@ public:
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void setImage(egl::Image *image); void setSharedImage(egl::Image *image);
virtual bool isSamplerComplete() const; virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const; virtual bool isCompressed(GLenum target, GLint level) const;
......
...@@ -4623,16 +4623,11 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) ...@@ -4623,16 +4623,11 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
return error(GL_INVALID_ENUM); return error(GL_INVALID_ENUM);
} }
if(!image)
{
return error(GL_INVALID_OPERATION);
}
es1::Context *context = es1::getContext(); es1::Context *context = es1::getContext();
if(context) if(context)
{ {
es1::Texture2D *texture = 0; es1::Texture2D *texture = nullptr;
switch(target) switch(target)
{ {
...@@ -4646,9 +4641,14 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) ...@@ -4646,9 +4641,14 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
egl::Image *glImage = static_cast<egl::Image*>(image); egl::Image *eglImage = context->getSharedImage(image);
if(!eglImage)
{
return error(GL_INVALID_OPERATION);
}
texture->setImage(glImage); texture->setSharedImage(eglImage);
} }
} }
......
...@@ -4263,7 +4263,12 @@ egl::Image *Context::createSharedImage(EGLenum target, GLuint name, GLuint textu ...@@ -4263,7 +4263,12 @@ egl::Image *Context::createSharedImage(EGLenum target, GLuint name, GLuint textu
} }
else UNREACHABLE(target); else UNREACHABLE(target);
return 0; return nullptr;
}
egl::Image *Context::getSharedImage(GLeglImageOES image)
{
return display->getSharedImage(image);
} }
Device *Context::getDevice() Device *Context::getDevice()
......
...@@ -688,6 +688,7 @@ public: ...@@ -688,6 +688,7 @@ public:
virtual void bindTexImage(egl::Surface *surface); virtual void bindTexImage(egl::Surface *surface);
virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel); virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel); virtual egl::Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel);
egl::Image *getSharedImage(GLeglImageOES image);
Device *getDevice(); Device *getDevice();
......
...@@ -810,7 +810,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo ...@@ -810,7 +810,7 @@ void Texture2D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
renderTarget->release(); renderTarget->release();
} }
void Texture2D::setImage(egl::Image *sharedImage) void Texture2D::setSharedImage(egl::Image *sharedImage)
{ {
if(sharedImage == image[0]) if(sharedImage == image[0])
{ {
...@@ -1775,7 +1775,7 @@ void Texture3D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo ...@@ -1775,7 +1775,7 @@ void Texture3D::copySubImage(GLenum target, GLint level, GLint xoffset, GLint yo
renderTarget->release(); renderTarget->release();
} }
void Texture3D::setImage(egl::Image *sharedImage) void Texture3D::setSharedImage(egl::Image *sharedImage)
{ {
sharedImage->addRef(); sharedImage->addRef();
......
...@@ -175,7 +175,7 @@ public: ...@@ -175,7 +175,7 @@ public:
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); void copyImage(GLint level, GLenum format, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); virtual void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void setImage(egl::Image *image); void setSharedImage(egl::Image *image);
virtual bool isSamplerComplete() const; virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const; virtual bool isCompressed(GLenum target, GLint level) const;
...@@ -295,7 +295,7 @@ public: ...@@ -295,7 +295,7 @@ public:
void copyImage(GLint level, GLenum format, GLint x, GLint y, GLint z, GLsizei width, GLsizei height, GLsizei depth, Framebuffer *source); void copyImage(GLint level, GLenum format, GLint x, GLint y, GLint z, GLsizei width, GLsizei height, GLsizei depth, Framebuffer *source);
void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source); void copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, Framebuffer *source);
void setImage(egl::Image *image); void setSharedImage(egl::Image *image);
virtual bool isSamplerComplete() const; virtual bool isSamplerComplete() const;
virtual bool isCompressed(GLenum target, GLint level) const; virtual bool isCompressed(GLenum target, GLint level) const;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <limits> #include <limits>
#ifdef ANDROID #ifdef __ANDROID__
#include <cutils/log.h> #include <cutils/log.h>
#endif #endif
...@@ -6682,16 +6682,11 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) ...@@ -6682,16 +6682,11 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
return error(GL_INVALID_ENUM); return error(GL_INVALID_ENUM);
} }
if(!image)
{
return error(GL_INVALID_OPERATION);
}
es2::Context *context = es2::getContext(); es2::Context *context = es2::getContext();
if(context) if(context)
{ {
es2::Texture2D *texture = 0; es2::Texture2D *texture = nullptr;
switch(target) switch(target)
{ {
...@@ -6705,9 +6700,14 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) ...@@ -6705,9 +6700,14 @@ void EGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
egl::Image *glImage = static_cast<egl::Image*>(image); egl::Image *eglImage = context->getSharedImage(image);
if(!eglImage)
{
return error(GL_INVALID_OPERATION);
}
texture->setImage(glImage); texture->setSharedImage(eglImage);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment