aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-02-24 11:57:23 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-24 18:28:32 +0000
commitfd8f4d502d7c7e861de7b361c8e13aacfbc49fb2 (patch)
treef7795296e25cbd7490c291ebdf3c8e57623d5edc
parente30f758525e39079dbfb5f8a8cf0c48898da10b1 (diff)
Fix some viewer crashes when switching color mode
The whole idea of immediate mode GUIs is to put your GUI code and the resulting action close together. Unfortunately, for actions that tear down the backend (possibly freeing the surfaces we're drawing to), we can't do that. So defer that action until the next frame (really, the next idle). Only required when an action might call setDisplayParams. BUG=skia: Change-Id: I3eb95fdb462526cb6d95819612ad2725c6f1050b Reviewed-on: https://skia-review.googlesource.com/8953 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r--tools/viewer/Viewer.cpp13
-rw-r--r--tools/viewer/Viewer.h2
2 files changed, 13 insertions, 2 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 535ece8b9e..e056b43ec4 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -934,8 +934,12 @@ void Viewer::drawImGui(SkCanvas* canvas) {
ImGui::RadioButton("Color Managed 8888", &newMode, 1);
ImGui::RadioButton("Color Managed F16", &newMode, 2);
if (newMode != oldMode) {
- this->setColorMode(2 == newMode ? kRGBA_F16_SkColorType : kN32_SkColorType,
- 0 != newMode);
+ // It isn't safe to switch color mode now (in the middle of painting). We might
+ // tear down the back-end, etc... Defer this change until the next onIdle.
+ fDeferredActions.push_back([=]() {
+ this->setColorMode(2 == newMode ? kRGBA_F16_SkColorType : kN32_SkColorType,
+ 0 != newMode);
+ });
}
// Pick from common gamuts:
@@ -1038,6 +1042,11 @@ void Viewer::drawImGui(SkCanvas* canvas) {
}
void Viewer::onIdle() {
+ for (int i = 0; i < fDeferredActions.count(); ++i) {
+ fDeferredActions[i]();
+ }
+ fDeferredActions.reset();
+
double startTime = SkTime::GetMSecs();
fAnimTimer.updateTime();
bool animateWantsInval = fSlides[fCurrentSlide]->animate(fAnimTimer);
diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h
index b17bd250db..1364592300 100644
--- a/tools/viewer/Viewer.h
+++ b/tools/viewer/Viewer.h
@@ -92,6 +92,8 @@ private:
SkMatrix fDefaultMatrix;
SkMatrix fDefaultMatrixInv;
+ SkTArray<std::function<void(void)>> fDeferredActions;
+
Json::Value fAllSlideNames; // cache all slide names for fast updateUIState
};