Revert "FPS and frame control for MSKP slide."
This reverts commit 3b7587814d
.
Reason for revert: Failing on Housekeeper-PerCommit-CreateDockerImage_Skia_Release:
obj/tools/viewer/viewer.MSKPSlide.o
../../tools/viewer/MSKPSlide.cpp:64:23: error: no member named 'clamp' in namespace 'std'
fFrame = std::clamp(fFrame, 0, fPlayer->numFrames() - 1);
Original change's description:
> FPS and frame control for MSKP slide.
>
> Bug: skia:11900
> Change-Id: Ib4d8da6a86da7966e613de2d7cfd61ff545b296a
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400676
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
TBR=jvanverth@google.com,bsalomon@google.com
Change-Id: I4a97deb1ac441f223977d2dbad2f93f5d4376a23
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:11900
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402777
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
This commit is contained in:
parent
3b7587814d
commit
a9d3cfbda2
@ -10,7 +10,6 @@
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkStream.h"
|
||||
#include "src/core/SkOSFile.h"
|
||||
#include "imgui.h"
|
||||
|
||||
MSKPSlide::MSKPSlide(const SkString& name, const SkString& path)
|
||||
: MSKPSlide(name, SkStream::MakeFromFile(path.c_str())) {}
|
||||
@ -25,71 +24,15 @@ SkISize MSKPSlide::getDimensions() const {
|
||||
}
|
||||
|
||||
void MSKPSlide::draw(SkCanvas* canvas) {
|
||||
if (!fPlayer) {
|
||||
ImGui::Text("Could not read mskp file %s.\n", fName.c_str());
|
||||
return;
|
||||
if (fPlayer) {
|
||||
fPlayer->playFrame(canvas, fFrame);
|
||||
}
|
||||
ImGui::Begin("MSKP");
|
||||
ImGui::BeginGroup();
|
||||
// Play/Pause button
|
||||
if (ImGui::Button(fPaused ? "Play " : "Pause")) {
|
||||
fPaused = !fPaused;
|
||||
if (fPaused) {
|
||||
// This will ensure that when playback is unpaused we start on the current frame.
|
||||
fLastFrameTime = -1;
|
||||
}
|
||||
}
|
||||
// Control the frame rate of MSKP playback
|
||||
ImGui::Text("FPS: "); ImGui::SameLine();
|
||||
ImGui::RadioButton( "1", &fFPS, 1); ImGui::SameLine();
|
||||
ImGui::RadioButton( "15", &fFPS, 15); ImGui::SameLine();
|
||||
ImGui::RadioButton( "30", &fFPS, 30); ImGui::SameLine();
|
||||
ImGui::RadioButton( "60", &fFPS, 60); ImGui::SameLine();
|
||||
ImGui::RadioButton("120", &fFPS, 120); ImGui::SameLine();
|
||||
ImGui::RadioButton("1:1", &fFPS, -1); // Draw one MSKP frame for each real viewer frame.
|
||||
if (fFPS < 0) {
|
||||
// Like above, will cause onAnimate() to resume at current frame when FPS is changed
|
||||
// back to another frame rate.
|
||||
fLastFrameTime = -1;
|
||||
}
|
||||
// Frame control. Slider and +/- buttons. Ctrl-Click slider to type frame number.
|
||||
ImGui::Text("Frame:");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushButtonRepeat(true); // Enable click-and-hold for frame arrows.
|
||||
if (ImGui::ArrowButton("-mksp_frame", ImGuiDir_Left)) {
|
||||
fFrame = (fFrame + fPlayer->numFrames() - 1)%fPlayer->numFrames();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::SliderInt("##msk_frameslider", &fFrame, 0, fPlayer->numFrames()-1, "% 3d")) {
|
||||
fFrame = std::clamp(fFrame, 0, fPlayer->numFrames() - 1);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::ArrowButton("+mskp_frame", ImGuiDir_Right)) {
|
||||
fFrame = (fFrame + 1)%fPlayer->numFrames();
|
||||
}
|
||||
ImGui::PopButtonRepeat();
|
||||
|
||||
fPlayer->playFrame(canvas, fFrame);
|
||||
ImGui::EndGroup();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
bool MSKPSlide::animate(double nanos) {
|
||||
if (!fPlayer || fPaused) {
|
||||
if (!fPlayer) {
|
||||
return false;
|
||||
}
|
||||
if (fLastFrameTime < 0) {
|
||||
// We're coming off being paused or switching from 1:1 mode to steady FPS. Advance 1 frame
|
||||
// and reset the frame time to start accumulating time from now.
|
||||
fFrame = (fFrame + 1)%fPlayer->numFrames();
|
||||
fLastFrameTime = nanos;
|
||||
return this->fPlayer->numFrames() > 1;
|
||||
}
|
||||
if (fFPS < 0) {
|
||||
// 1:1 mode. Always draw the next frame on each animation cycle.
|
||||
fFrame = (fFrame + 1)%fPlayer->numFrames();
|
||||
return this->fPlayer->numFrames() > 1;
|
||||
}
|
||||
double elapsed = nanos - fLastFrameTime;
|
||||
double frameTime = 1E9/fFPS;
|
||||
int framesToAdvance = elapsed/frameTime;
|
||||
@ -101,10 +44,15 @@ bool MSKPSlide::animate(double nanos) {
|
||||
|
||||
void MSKPSlide::load(SkScalar, SkScalar) {
|
||||
if (!fStream) {
|
||||
SkDebugf("No skp stream for slide %s.\n", fName.c_str());
|
||||
return;
|
||||
}
|
||||
fStream->rewind();
|
||||
fPlayer = MSKPPlayer::Make(fStream.get());
|
||||
if (!fPlayer) {
|
||||
SkDebugf("Could parse MSKP from stream for slide %s.\n", fName.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MSKPSlide::unload() { fPlayer.reset(); }
|
||||
|
@ -28,12 +28,10 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<SkStreamSeekable> fStream;
|
||||
std::unique_ptr<MSKPPlayer> fPlayer;
|
||||
|
||||
int fFrame = 0;
|
||||
int fFPS = 15;
|
||||
bool fPaused = false;
|
||||
double fLastFrameTime = -1;
|
||||
std::unique_ptr<MSKPPlayer> fPlayer;
|
||||
int fFrame = 0;
|
||||
int fFPS = 15; // TODO: make this adjustable. This happens to work well for calendar.mskp
|
||||
double fLastFrameTime = 0;
|
||||
|
||||
using INHERITED = Slide;
|
||||
};
|
||||
|
@ -36,6 +36,7 @@ public:
|
||||
|
||||
const SkString& getName() { return fName; }
|
||||
|
||||
|
||||
protected:
|
||||
SkString fName;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user