283dba5785
This reverts commit e58831cd95
.
Reason for revert: looks like breaking a few build bots
Original change's description:
> Add format-specifier warnings to SkDebugf.
>
> This CL fixes up many existing format-specifier violations in Skia.
> Note that GCC has a warning for formatting nothing, so existing calls to
> `SkDebugf("")` have been removed, or replaced with `SkDebugf("%s", "")`.
> These were apparently meant to be used as a place to set a breakpoint.
>
> Some of our clients also use SkDebug with bad format specifiers, so this
> check is currently only enabled when SKIA_IMPLEMENTATION is true.
>
> Change-Id: I8177a1298a624c6936adc24e0d8f481362a356d0
> Bug: skia:12143
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/420902
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
TBR=brianosman@google.com,ethannicholas@google.com,johnstiles@google.com
Change-Id: I07848c1bf8992925c9498e916744d0840355a077
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:12143
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/421917
Reviewed-by: Tyler Denniston <tdenniston@google.com>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
96 lines
2.7 KiB
C++
96 lines
2.7 KiB
C++
/*
|
|
* Copyright 2020 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkData.h"
|
|
#include "modules/audioplayer/SkAudioPlayer.h"
|
|
#include "samplecode/Sample.h"
|
|
#include "src/core/SkUtils.h"
|
|
#include "tools/Resources.h"
|
|
|
|
class AudioView : public Sample {
|
|
std::unique_ptr<SkAudioPlayer> fPlayer;
|
|
SkRect fBar;
|
|
|
|
public:
|
|
AudioView() {}
|
|
|
|
protected:
|
|
SkString name() override { return SkString("Audio"); }
|
|
|
|
void onOnceBeforeDraw() override {
|
|
auto data = SkData::MakeFromFileName("/Users/reed/skia/mp3/scott-joplin-peacherine-rag.mp3");
|
|
if (data) {
|
|
fPlayer = SkAudioPlayer::Make(data);
|
|
|
|
SkDebugf("make: dur:%g time%g state:%d",
|
|
fPlayer->duration(),
|
|
fPlayer->time(),
|
|
fPlayer->state());
|
|
}
|
|
|
|
fBar = { 10, 10, 510, 30 };
|
|
}
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
if (!fPlayer) {
|
|
return;
|
|
}
|
|
|
|
SkPaint p;
|
|
p.setColor(0xFFCCCCCC);
|
|
canvas->drawRect(fBar, p);
|
|
|
|
p.setColor(fPlayer->isPlaying() ? SK_ColorBLUE : 0xFF8888FF);
|
|
SkRect r = fBar;
|
|
r.fRight = r.fLeft + (float)fPlayer->normalizedTime() * r.width();
|
|
canvas->drawRect(r, p);
|
|
}
|
|
|
|
bool onChar(SkUnichar c) override {
|
|
if (c == ' ') {
|
|
switch (fPlayer->state()) {
|
|
case SkAudioPlayer::State::kPlaying: fPlayer->pause(); break;
|
|
case SkAudioPlayer::State::kPaused: fPlayer->play(); break;
|
|
case SkAudioPlayer::State::kStopped: fPlayer->play(); break;
|
|
}
|
|
return true;
|
|
}
|
|
return this->INHERITED::onChar(c);
|
|
}
|
|
|
|
Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
|
|
if (fPlayer && fBar.contains(x, y)) {
|
|
bool wasPlaying = fPlayer->isPlaying();
|
|
if (wasPlaying) {
|
|
fPlayer->pause();
|
|
}
|
|
return new Click([this, wasPlaying](Click* click) {
|
|
if (fBar.contains(click->fCurr.fX, click->fCurr.fY)) {
|
|
fPlayer->setNormalizedTime((click->fCurr.fX - fBar.fLeft) / fBar.width());
|
|
}
|
|
|
|
if (click->fState == skui::InputState::kUp) {
|
|
if (wasPlaying) {
|
|
fPlayer->play();
|
|
}
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
bool onAnimate(double /*nanos*/) override {
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
using INHERITED = Sample;
|
|
};
|
|
DEF_SAMPLE( return new AudioView; )
|