Present should return OUT_OF_DATE if the window size outdated
This is the correct behavior according to the spec. This CL modifies
MetalSurface, XcbSurfaceKHR and XlibSurfaceKHR.
Bug: swiftshader: 140
Change-Id: I3f1829506a9d95c11c07f6a3a9ea1e7557e78725
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38648
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Jonah Ryan-Davis <jonahr@google.com>
diff --git a/src/WSI/MetalSurface.mm b/src/WSI/MetalSurface.mm
index 1db25f3..6aec803 100644
--- a/src/WSI/MetalSurface.mm
+++ b/src/WSI/MetalSurface.mm
@@ -144,7 +144,14 @@
auto drawable = metalLayer->getNextDrawable();
if(drawable)
{
+ VkExtent2D windowExtent = metalLayer->getExtent();
VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+
+ if (windowExtent.width != extent.width || windowExtent.height != extent.height)
+ {
+ return VK_ERROR_OUT_OF_DATE_KHR;
+ }
+
[drawable.texture replaceRegion:MTLRegionMake2D(0, 0, extent.width, extent.height)
mipmapLevel:0
withBytes:image->getImageMemory()->getOffsetPointer(0)
diff --git a/src/WSI/XcbSurfaceKHR.cpp b/src/WSI/XcbSurfaceKHR.cpp
index f6d4417..db68358 100644
--- a/src/WSI/XcbSurfaceKHR.cpp
+++ b/src/WSI/XcbSurfaceKHR.cpp
@@ -144,8 +144,17 @@
auto it = graphicsContexts.find(image);
if(it != graphicsContexts.end())
{
- // TODO: Convert image if not RGB888.
+ auto geom = libXcb->xcb_get_geometry_reply(connection, libXcb->xcb_get_geometry(connection, window), nullptr);
+ VkExtent2D windowExtent = {static_cast<uint32_t>(geom->width), static_cast<uint32_t>(geom->height)};
+ free(geom);
VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+
+ if (windowExtent.width != extent.width || windowExtent.height != extent.height)
+ {
+ return VK_ERROR_OUT_OF_DATE_KHR;
+ }
+
+ // TODO: Convert image if not RGB888.
int stride = image->getImage()->rowPitchBytes(VK_IMAGE_ASPECT_COLOR_BIT, 0);
auto buffer = reinterpret_cast<uint8_t*>(image->getImageMemory()->getOffsetPointer(0));
size_t bufferSize = extent.height * stride;
diff --git a/src/WSI/XlibSurfaceKHR.cpp b/src/WSI/XlibSurfaceKHR.cpp
index d40088a..b3a0275 100644
--- a/src/WSI/XlibSurfaceKHR.cpp
+++ b/src/WSI/XlibSurfaceKHR.cpp
@@ -91,7 +91,16 @@
if(xImage->data)
{
+ XWindowAttributes attr;
+ libX11->XGetWindowAttributes(pDisplay, window, &attr);
+ VkExtent2D windowExtent = {static_cast<uint32_t>(attr.width), static_cast<uint32_t>(attr.height)};
VkExtent3D extent = image->getImage()->getMipLevelExtent(VK_IMAGE_ASPECT_COLOR_BIT, 0);
+
+ if (windowExtent.width != extent.width || windowExtent.height != extent.height)
+ {
+ return VK_ERROR_OUT_OF_DATE_KHR;
+ }
+
libX11->XPutImage(pDisplay, window, gc, xImage, 0, 0, 0, 0, extent.width, extent.height);
}
}