Add option to disable vsync on viewer unix.
This also fixes an issue where vulkan would crash any time we change a display param on unix. Bug: skia: Change-Id: Ic6c3843e04bc77c2e9c5301ee38fcc58a409495d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/203380 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
65f3344294
commit
bb792aae8c
@ -19,6 +19,7 @@ struct DisplayParams {
|
||||
, fColorSpace(nullptr)
|
||||
, fMSAASampleCount(1)
|
||||
, fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
|
||||
, fDisableVsync(false)
|
||||
{}
|
||||
|
||||
SkColorType fColorType;
|
||||
@ -26,6 +27,7 @@ struct DisplayParams {
|
||||
int fMSAASampleCount;
|
||||
GrContextOptions fGrContextOptions;
|
||||
SkSurfaceProps fSurfaceProps;
|
||||
bool fDisableVsync;
|
||||
};
|
||||
|
||||
} // namespace sk_app
|
||||
|
@ -262,12 +262,18 @@ bool VulkanWindowContext::createSwapchain(int width, int height,
|
||||
// If mailbox mode is available, use it, as it is the lowest-latency non-
|
||||
// tearing mode. If not, fall back to FIFO which is always available.
|
||||
VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
bool hasImmediate = false;
|
||||
for (uint32_t i = 0; i < presentModeCount; ++i) {
|
||||
// use mailbox
|
||||
if (VK_PRESENT_MODE_MAILBOX_KHR == presentModes[i]) {
|
||||
mode = presentModes[i];
|
||||
break;
|
||||
mode = VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
}
|
||||
if (VK_PRESENT_MODE_IMMEDIATE_KHR == presentModes[i]) {
|
||||
hasImmediate = true;
|
||||
}
|
||||
}
|
||||
if (params.fDisableVsync && hasImmediate) {
|
||||
mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
|
||||
VkSwapchainCreateInfoKHR swapchainCreateInfo;
|
||||
|
@ -67,6 +67,7 @@ sk_sp<const GrGLInterface> GLWindowContext_xlib::onInitializeContext() {
|
||||
SkASSERT(!fGLContext);
|
||||
sk_sp<const GrGLInterface> interface;
|
||||
bool current = false;
|
||||
|
||||
// We attempt to use glXCreateContextAttribsARB as RenderDoc requires that the context be
|
||||
// created with this rather than glXCreateContext.
|
||||
CreateContextAttribsFn* createContextAttribs = (CreateContextAttribsFn*)glXGetProcAddressARB(
|
||||
@ -126,6 +127,17 @@ sk_sp<const GrGLInterface> GLWindowContext_xlib::onInitializeContext() {
|
||||
if (!current && !glXMakeCurrent(fDisplay, fWindow, fGLContext)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* glxExtensions = glXQueryExtensionsString(fDisplay, DefaultScreen(fDisplay));
|
||||
if (glxExtensions) {
|
||||
if (strstr(glxExtensions, "GLX_EXT_swap_control")) {
|
||||
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT =
|
||||
(PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB(
|
||||
(const GLubyte*)"glXSwapIntervalEXT");
|
||||
glXSwapIntervalEXT(fDisplay, fWindow, fDisplayParams.fDisableVsync ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
glClearStencil(0);
|
||||
glClearColor(0, 0, 0, 0);
|
||||
glStencilMask(0xffffffff);
|
||||
|
@ -333,6 +333,8 @@ void Window_unix::show() {
|
||||
}
|
||||
|
||||
bool Window_unix::attach(BackendType attachType) {
|
||||
fBackend = attachType;
|
||||
|
||||
this->initWindow(fDisplay);
|
||||
|
||||
window_context_factory::XlibWindowInfo winInfo;
|
||||
@ -384,4 +386,21 @@ void Window_unix::onInval() {
|
||||
XSendEvent(fDisplay, fWindow, False, 0, &event);
|
||||
}
|
||||
|
||||
void Window_unix::setRequestedDisplayParams(const DisplayParams& params, bool allowReattach) {
|
||||
#if defined(SK_VULKAN)
|
||||
// Vulkan on unix crashes if we try to reinitialize the vulkan context without remaking the
|
||||
// window.
|
||||
if (fBackend == kVulkan_BackendType && allowReattach) {
|
||||
// Need to change these early, so attach() creates the window context correctly
|
||||
fRequestedDisplayParams = params;
|
||||
|
||||
this->detach();
|
||||
this->attach(fBackend);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
INHERITED::setRequestedDisplayParams(params, allowReattach);
|
||||
}
|
||||
|
||||
} // namespace sk_app
|
||||
|
@ -74,6 +74,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void setRequestedDisplayParams(const DisplayParams&, bool allowReattach) override;
|
||||
|
||||
private:
|
||||
void closeWindow();
|
||||
|
||||
@ -90,6 +92,10 @@ private:
|
||||
int fPendingWidth;
|
||||
int fPendingHeight;
|
||||
bool fPendingResize;
|
||||
|
||||
BackendType fBackend;
|
||||
|
||||
typedef Window INHERITED;
|
||||
};
|
||||
|
||||
} // namespace sk_app
|
||||
|
@ -406,6 +406,13 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
|
||||
this->updateTitle();
|
||||
fWindow->inval();
|
||||
});
|
||||
fCommands.addCommand('v', "VSync", "Toggle vsync on/off", [this]() {
|
||||
DisplayParams params = fWindow->getRequestedDisplayParams();
|
||||
params.fDisableVsync = !params.fDisableVsync;
|
||||
fWindow->setRequestedDisplayParams(params);
|
||||
this->updateTitle();
|
||||
fWindow->inval();
|
||||
});
|
||||
fCommands.addCommand('H', "Font", "Hinting mode", [this]() {
|
||||
if (!fFontOverrides.fHinting) {
|
||||
fFontOverrides.fHinting = true;
|
||||
|
Loading…
Reference in New Issue
Block a user