Commit 79c7e273 by Nicolas Capens

Implement EGL_LARGEST_PBUFFER.

Bug 23041720 Change-Id: I9f6bed0a3d239a0adde9cc4e90cc368f078f3662 Reviewed-on: https://swiftshader-review.googlesource.com/3902Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent f77786ef
......@@ -305,7 +305,7 @@ EGLSurface Display::createWindowSurface(EGLNativeWindowType window, EGLConfig co
return error(EGL_BAD_ALLOC, EGL_NO_SURFACE);
}
Surface *surface = new Surface(this, configuration, window);
Surface *surface = new WindowSurface(this, configuration, window);
if(!surface->initialize())
{
......@@ -319,61 +319,63 @@ EGLSurface Display::createWindowSurface(EGLNativeWindowType window, EGLConfig co
return success(surface);
}
EGLSurface Display::createOffscreenSurface(EGLConfig config, const EGLint *attribList)
EGLSurface Display::createPBufferSurface(EGLConfig config, const EGLint *attribList)
{
EGLint width = 0, height = 0;
EGLenum textureFormat = EGL_NO_TEXTURE;
EGLenum textureTarget = EGL_NO_TEXTURE;
EGLBoolean largestPBuffer = EGL_FALSE;
const Config *configuration = mConfigSet.get(config);
if(attribList)
{
while(*attribList != EGL_NONE)
{
switch (attribList[0])
switch(attribList[0])
{
case EGL_WIDTH:
case EGL_WIDTH:
width = attribList[1];
break;
case EGL_HEIGHT:
case EGL_HEIGHT:
height = attribList[1];
break;
case EGL_LARGEST_PBUFFER:
if(attribList[1] != EGL_FALSE)
UNIMPLEMENTED(); // FIXME
case EGL_LARGEST_PBUFFER:
largestPBuffer = attribList[1];
break;
case EGL_TEXTURE_FORMAT:
switch (attribList[1])
case EGL_TEXTURE_FORMAT:
switch(attribList[1])
{
case EGL_NO_TEXTURE:
case EGL_TEXTURE_RGB:
case EGL_TEXTURE_RGBA:
case EGL_NO_TEXTURE:
case EGL_TEXTURE_RGB:
case EGL_TEXTURE_RGBA:
textureFormat = attribList[1];
break;
default:
default:
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
}
break;
case EGL_TEXTURE_TARGET:
switch (attribList[1])
case EGL_TEXTURE_TARGET:
switch(attribList[1])
{
case EGL_NO_TEXTURE:
case EGL_TEXTURE_2D:
case EGL_NO_TEXTURE:
case EGL_TEXTURE_2D:
textureTarget = attribList[1];
break;
default:
default:
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
}
break;
case EGL_MIPMAP_TEXTURE:
case EGL_MIPMAP_TEXTURE:
if(attribList[1] != EGL_FALSE)
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
{
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
}
break;
case EGL_VG_COLORSPACE:
case EGL_VG_COLORSPACE:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
case EGL_VG_ALPHA_FORMAT:
case EGL_VG_ALPHA_FORMAT:
return error(EGL_BAD_MATCH, EGL_NO_SURFACE);
default:
default:
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
}
......@@ -408,7 +410,7 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, const EGLint *attri
return error(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
}
Surface *surface = new Surface(this, configuration, width, height, textureFormat, textureTarget);
Surface *surface = new PBufferSurface(this, configuration, width, height, textureFormat, textureTarget, largestPBuffer);
if(!surface->initialize())
{
......@@ -543,21 +545,24 @@ bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
{
for(SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
{
if((*surface)->getWindowHandle() == window)
{
return true;
}
if((*surface)->isWindowSurface())
{
if((*surface)->getWindowHandle() == window)
{
return true;
}
}
}
return false;
}
EGLint Display::getMinSwapInterval()
EGLint Display::getMinSwapInterval() const
{
return mMinSwapInterval;
}
EGLint Display::getMaxSwapInterval()
EGLint Display::getMaxSwapInterval() const
{
return mMaxSwapInterval;
}
......
......@@ -39,7 +39,7 @@ namespace egl
bool getConfigAttrib(EGLConfig config, EGLint attribute, EGLint *value);
EGLSurface createWindowSurface(EGLNativeWindowType window, EGLConfig config, const EGLint *attribList);
EGLSurface createOffscreenSurface(EGLConfig config, const EGLint *attribList);
EGLSurface createPBufferSurface(EGLConfig config, const EGLint *attribList);
EGLContext createContext(EGLConfig configHandle, const Context *shareContext, EGLint clientVersion);
void destroySurface(Surface *surface);
......@@ -52,8 +52,8 @@ namespace egl
bool isValidWindow(EGLNativeWindowType window);
bool hasExistingWindowSurface(EGLNativeWindowType window);
EGLint getMinSwapInterval();
EGLint getMaxSwapInterval();
EGLint getMinSwapInterval() const;
EGLint getMaxSwapInterval() const;
EGLNativeDisplayType getNativeDisplay() const;
const char *getExtensionString() const;
......
......@@ -31,13 +31,8 @@ class Image;
class Surface : public gl::Object
{
public:
Surface(Display *display, const egl::Config *config, EGLNativeWindowType window);
Surface(Display *display, const egl::Config *config, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget);
bool initialize();
void swap();
EGLNativeWindowType getWindowHandle();
virtual bool initialize();
virtual void swap() = 0;
virtual egl::Image *getRenderTarget();
virtual egl::Image *getDepthStencil();
......@@ -56,45 +51,78 @@ public:
virtual EGLenum getSwapBehavior() const;
virtual EGLenum getTextureFormat() const;
virtual EGLenum getTextureTarget() const;
virtual EGLBoolean getLargestPBuffer() const;
virtual EGLNativeWindowType getWindowHandle() const = 0;
virtual void setBoundTexture(egl::Texture *texture);
virtual egl::Texture *getBoundTexture() const;
bool checkForResize(); // Returns true if surface changed due to resize
virtual bool isWindowSurface() const { return false; }
virtual bool isPBufferSurface() const { return false; }
protected:
Surface(const Display *display, const Config *config);
private:
virtual ~Surface();
void deleteResources();
bool reset();
virtual void deleteResources();
Display *const mDisplay;
egl::Image *mDepthStencil;
sw::FrameBuffer *frameBuffer;
egl::Image *backBuffer;
egl::Texture *mTexture;
const Display *const display;
Image *depthStencil;
Image *backBuffer;
Texture *texture;
bool reset(int backbufferWidth, int backbufferHeight);
const EGLNativeWindowType mWindow; // Window that the surface is created for.
bool mWindowSubclassed; // Indicates whether we successfully subclassed mWindow for WM_RESIZE hooking
const egl::Config *mConfig; // EGL config surface was created with
EGLint mHeight; // Height of surface
EGLint mWidth; // Width of surface
// EGLint horizontalResolution; // Horizontal dot pitch
// EGLint verticalResolution; // Vertical dot pitch
// EGLBoolean largestPBuffer; // If true, create largest pbuffer possible
// EGLBoolean mipmapTexture; // True if texture has mipmaps
// EGLint mipmapLevel; // Mipmap level to render to
// EGLenum multisampleResolve; // Multisample resolve behavior
EGLint mPixelAspectRatio; // Display aspect ratio
EGLenum mRenderBuffer; // Render buffer
EGLenum mSwapBehavior; // Buffer swap behavior
EGLenum mTextureFormat; // Format of texture: RGB, RGBA, or no texture
EGLenum mTextureTarget; // Type of texture: 2D or no texture
// EGLenum vgAlphaFormat; // Alpha format for OpenVG
// EGLenum vgColorSpace; // Color space for OpenVG
EGLint mSwapInterval;
const Config *const config; // EGL config surface was created with
EGLint height; // Height of surface
EGLint width; // Width of surface
// EGLint horizontalResolution; // Horizontal dot pitch
// EGLint verticalResolution; // Vertical dot pitch
EGLBoolean largestPBuffer; // If true, create largest pbuffer possible
// EGLBoolean mipmapTexture; // True if texture has mipmaps
// EGLint mipmapLevel; // Mipmap level to render to
// EGLenum multisampleResolve; // Multisample resolve behavior
EGLint pixelAspectRatio; // Display aspect ratio
EGLenum renderBuffer; // Render buffer
EGLenum swapBehavior; // Buffer swap behavior
EGLenum textureFormat; // Format of texture: RGB, RGBA, or no texture
EGLenum textureTarget; // Type of texture: 2D or no texture
// EGLenum vgAlphaFormat; // Alpha format for OpenVG
// EGLenum vgColorSpace; // Color space for OpenVG
EGLint swapInterval;
};
class WindowSurface : public Surface
{
public:
WindowSurface(Display *display, const egl::Config *config, EGLNativeWindowType window);
bool initialize() override;
bool isWindowSurface() const override { return true; }
void swap() override;
EGLNativeWindowType getWindowHandle() const override;
private:
void deleteResources() override;
bool checkForResize();
bool reset(int backBufferWidth, int backBufferHeight);
const EGLNativeWindowType window;
sw::FrameBuffer *frameBuffer;
};
class PBufferSurface : public Surface
{
public:
PBufferSurface(Display *display, const egl::Config *config, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget, EGLBoolean largestPBuffer);
bool isPBufferSurface() const override { return true; }
void swap() override;
EGLNativeWindowType getWindowHandle() const override;
};
}
......
......@@ -302,7 +302,7 @@ EGLSurface CreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *
return EGL_NO_SURFACE;
}
return display->createOffscreenSurface(config, attrib_list);
return display->createPBufferSurface(config, attrib_list);
}
EGLSurface CreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
......@@ -380,7 +380,10 @@ EGLBoolean QuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EG
UNIMPLEMENTED(); // FIXME
break;
case EGL_LARGEST_PBUFFER:
UNIMPLEMENTED(); // FIXME
if(eglSurface->isPBufferSurface()) // For a window or pixmap surface, the contents of *value are not modified.
{
*value = eglSurface->getLargestPBuffer();
}
break;
case EGL_MIPMAP_TEXTURE:
UNIMPLEMENTED(); // FIXME
......@@ -530,7 +533,7 @@ EGLBoolean BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
return error(EGL_BAD_PARAMETER, EGL_FALSE);
}
if(surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
if(surface == EGL_NO_SURFACE || eglSurface->isWindowSurface())
{
return error(EGL_BAD_SURFACE, EGL_FALSE);
}
......@@ -572,7 +575,7 @@ EGLBoolean ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
return error(EGL_BAD_PARAMETER, EGL_FALSE);
}
if(surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
if(surface == EGL_NO_SURFACE || eglSurface->isWindowSurface())
{
return error(EGL_BAD_SURFACE, EGL_FALSE);
}
......
......@@ -2129,7 +2129,7 @@ void Context::applyTextures(sw::SamplerType samplerType)
}
else
{
applyTexture(samplerType, samplerIndex, 0);
applyTexture(samplerType, samplerIndex, nullptr);
device->setStageOperation(samplerIndex, sw::TextureStage::STAGE_SELECTARG1);
device->setFirstArgument(samplerIndex, sw::TextureStage::SOURCE_CURRENT);
......@@ -2144,7 +2144,7 @@ void Context::applyTextures(sw::SamplerType samplerType)
}
else
{
applyTexture(samplerType, samplerIndex, NULL);
applyTexture(samplerType, samplerIndex, nullptr);
}
}
}
......
......@@ -2238,7 +2238,7 @@ void Context::applyTextures()
}
else
{
applyTexture(unit, 0);
applyTexture(unit, nullptr);
device->setFirstArgument(unit, sw::TextureStage::SOURCE_CURRENT);
device->setFirstModifier(unit, sw::TextureStage::MODIFIER_COLOR);
......
......@@ -90,17 +90,9 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLsizei count, Buffer *bu
}
intptr_t offset = reinterpret_cast<intptr_t>(indices);
bool alignedOffset = false;
if(buffer != NULL)
{
switch(type)
{
case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break;
case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break;
default: UNREACHABLE(type); alignedOffset = false;
}
if(typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size()))
{
return GL_INVALID_OPERATION;
......
......@@ -3083,12 +3083,12 @@ void Context::applyTextures(sw::SamplerType samplerType)
}
else
{
applyTexture(samplerType, samplerIndex, 0);
applyTexture(samplerType, samplerIndex, nullptr);
}
}
else
{
applyTexture(samplerType, samplerIndex, NULL);
applyTexture(samplerType, samplerIndex, nullptr);
}
}
}
......
......@@ -98,18 +98,9 @@ GLenum IndexDataManager::prepareIndexData(GLenum type, GLuint start, GLuint end,
}
intptr_t offset = reinterpret_cast<intptr_t>(indices);
bool alignedOffset = false;
if(buffer != NULL)
{
switch(type)
{
case GL_UNSIGNED_BYTE: alignedOffset = (offset % sizeof(GLubyte) == 0); break;
case GL_UNSIGNED_SHORT: alignedOffset = (offset % sizeof(GLushort) == 0); break;
case GL_UNSIGNED_INT: alignedOffset = (offset % sizeof(GLuint) == 0); break;
default: UNREACHABLE(type); alignedOffset = false;
}
if(typeSize(type) * count + offset > static_cast<std::size_t>(buffer->size()))
{
return GL_INVALID_OPERATION;
......
......@@ -77,14 +77,14 @@ static bool validateSubImageParams(bool compressed, GLsizei width, GLsizei heigh
if(compressed)
{
if((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
(height % 4 != 0 && height != texture->getHeight(target, 0)))
(height % 4 != 0 && height != texture->getHeight(target, 0)))
{
return error(GL_INVALID_OPERATION, false);
}
}
if(xoffset + width > texture->getWidth(target, level) ||
yoffset + height > texture->getHeight(target, level))
yoffset + height > texture->getHeight(target, level))
{
return error(GL_INVALID_VALUE, false);
}
......
......@@ -73,7 +73,7 @@ static bool validateSubImageParams(bool compressed, GLsizei width, GLsizei heigh
}
if(xoffset + width > texture->getWidth(target, level) ||
yoffset + height > texture->getHeight(target, level))
yoffset + height > texture->getHeight(target, level))
{
return error(GL_INVALID_VALUE, false);
}
......@@ -101,8 +101,8 @@ static bool validateSubImageParams(bool compressed, GLsizei width, GLsizei heigh
if(compressed)
{
if((width % 4 != 0 && width != texture->getWidth(target, 0)) ||
(height % 4 != 0 && height != texture->getHeight(target, 0)) ||
(depth % 4 != 0 && depth != texture->getDepth(target, 0)))
(height % 4 != 0 && height != texture->getHeight(target, 0)) ||
(depth % 4 != 0 && depth != texture->getDepth(target, 0)))
{
return error(GL_INVALID_OPERATION, false);
}
......@@ -124,10 +124,10 @@ static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFo
{
case GL_ALPHA:
if(colorbufferFormat != GL_ALPHA &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
{
return error(GL_INVALID_OPERATION, false);
}
......@@ -135,12 +135,12 @@ static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFo
case GL_LUMINANCE:
case GL_RGB:
if(colorbufferFormat != GL_RGB &&
colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8 &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
colorbufferFormat != GL_RGB565 &&
colorbufferFormat != GL_RGB8 &&
colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
{
return error(GL_INVALID_OPERATION, false);
}
......@@ -148,9 +148,9 @@ static bool validateColorBufferFormat(GLenum textureFormat, GLenum colorbufferFo
case GL_LUMINANCE_ALPHA:
case GL_RGBA:
if(colorbufferFormat != GL_RGBA &&
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
colorbufferFormat != GL_RGBA4 &&
colorbufferFormat != GL_RGB5_A1 &&
colorbufferFormat != GL_RGBA8)
{
return error(GL_INVALID_OPERATION, false);
}
......
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