30#if defined(SK_ENABLE_SKOTTIE)
32static DEFINE_string(animatedGif,
"images/test640x479.gif",
"Animated gif in resources folder");
36 std::unique_ptr<SkCodec> fCodec;
40 std::vector<SkCodec::FrameInfo> fFrameInfos;
41 std::vector<SkBitmap> fFrames;
43 void drawFrame(
SkCanvas* canvas,
int frameIndex) {
45 if (frameIndex >= (
int) fFrames.size()) {
46 fFrames.resize(frameIndex + 1);
50 const SkImageInfo info = fCodec->getInfo().makeColorType(kN32_SkColorType);
55 const int requiredFrame = fFrameInfos[frameIndex].fRequiredFrame;
58 &&
static_cast<size_t>(requiredFrame) < fFrames.size());
59 SkBitmap& requiredBitmap = fFrames[requiredFrame];
69 SkDebugf(
"Could not getPixels for frame %i: %s", frameIndex, FLAGS_animatedGif[0]);
81 , fTotalFrames (-1) {}
87 if (this->initCodec()) {
88 SkISize dim = fCodec->getInfo().dimensions();
90 dim.
fWidth *= fTotalFrames;
102 if (FLAGS_animatedGif.isEmpty()) {
103 SkDebugf(
"Nothing specified for --animatedGif!");
118 fFrameInfos = fCodec->getFrameInfo();
119 fTotalFrames = fFrameInfos.size();
124 if (!this->initCodec()) {
125 errorMsg->
printf(
"Could not create codec from %s", FLAGS_animatedGif[0]);
130 for (
int frameIndex = 0; frameIndex < fTotalFrames; frameIndex++) {
131 this->drawFrame(canvas, frameIndex);
138 this->drawFrame(canvas, fFrame);
143 if (!fCodec || fTotalFrames == 1) {
148 if (fNextUpdate <
double(0)) {
153 fNextUpdate = secs + fFrameInfos[fFrame].fDuration;
158 if (secs < fNextUpdate) {
162 while (secs >= fNextUpdate) {
165 if (fFrame == fTotalFrames) {
171 fNextUpdate += fFrameInfos[fFrame].fDuration;
177DEF_GM(
return new AnimatedGifGM;)
179static std::unique_ptr<SkCodec> load_codec(
const char filename[]) {
185 std::vector<std::unique_ptr<SkAnimCodecPlayer> > fPlayers;
186 uint32_t fBaseMSec = 0;
189 AnimCodecPlayerGM() {
190 const char*
root =
"/skia/anim/";
193 while (iter.next(&
path)) {
196 auto codec = load_codec(completepath.
c_str());
198 fPlayers.push_back(std::make_unique<SkAnimCodecPlayer>(std::move(codec)));
209 canvas->
scale(0.25f, 0.25f);
210 for (
auto&
p : fPlayers) {
212 canvas->
translate(
p->dimensions().width(), 0);
217 if (fBaseMSec == 0) {
220 for (
auto&
p : fPlayers) {
226DEF_GM(
return new AnimCodecPlayerGM;)
228class AnimCodecPlayerExifGM :
public skiagm::GM {
231 std::unique_ptr<SkAnimCodecPlayer> fPlayer;
232 std::vector<SkCodec::FrameInfo> fFrameInfos;
240 fFrameInfos = codec->getFrameInfo();
241 fPlayer = std::make_unique<SkAnimCodecPlayer>(std::move(codec));
242 if (!fPlayer)
return;
247 const size_t count = fFrameInfos.size();
251 auto imageSize = fPlayer->dimensions();
252 fSize.fWidth = imageSize.fWidth * factor;
266 void onDraw(
SkCanvas* canvas)
override {
268 if (!fPlayer)
return;
270 const float root =
sqrt((
float) fFrameInfos.size());
272 auto dimensions = fPlayer->dimensions();
277 const int xTranslate = (
frame % factor) * dimensions.width();
278 const int yTranslate = (
frame / factor) * dimensions.height();
282 auto image = fPlayer->getFrame();
289 AnimCodecPlayerExifGM(
const char*
path)
293 ~AnimCodecPlayerExifGM()
override =
default;
296DEF_GM(
return new AnimCodecPlayerExifGM(
"images/required.webp");)
297DEF_GM(
return new AnimCodecPlayerExifGM(
"images/required.gif");)
298DEF_GM(
return new AnimCodecPlayerExifGM(
"images/stoplight_h.webp");)
#define DEFINE_string(name, defaultValue, helpString)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
sk_sp< SkData > GetResourceAsData(const char *resource)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define sk_float_ceil2int(x)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
void allocPixels(const SkImageInfo &info, size_t rowBytes)
sk_sp< SkImage > asImage() const
SkColorType colorType() const
void translate(SkScalar dx, SkScalar dy)
void scale(SkScalar sx, SkScalar sy)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
static constexpr int kNoFrame
static sk_sp< SkData > MakeFromFileName(const char path[])
void printf(const char format[],...) SK_PRINTF_LIKE(2
const char * c_str() const
virtual SkISize getISize()=0
virtual SkString getName() const =0
virtual bool onAnimate(double)
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
sk_sp< const SkImage > image
static SkMSec NanosToMSec(double nanos)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
static constexpr SkISize MakeEmpty()
static constexpr SkISize Make(int32_t w, int32_t h)
std::shared_ptr< const fml::Mapping > data