skia2/include/utils/SkAnimCodecPlayer.h
Kevin Lubick 62f57a02b3 [includes] Enforce IWYU on src/utils
Client changes:
 - cl/443664347
 - cl/444232853
 - http://ag/17915718
 - http://ag/17913178
 - https://crrev.com/c/3602239

Change-Id: I16bcdbbe2b13bbf52f007b0f131e9ee0c14ed237
Bug: skia:13052
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532257
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-04-28 17:32:20 +00:00

68 lines
1.9 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkAnimCodecPlayer_DEFINED
#define SkAnimCodecPlayer_DEFINED
#include "include/codec/SkCodec.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include <stdint.h>
#include <memory>
#include <vector>
class SkImage;
class SkAnimCodecPlayer {
public:
SkAnimCodecPlayer(std::unique_ptr<SkCodec> codec);
~SkAnimCodecPlayer();
/**
* Returns the current frame of the animation. This defaults to the first frame for
* animated codecs (i.e. msec = 0). Calling this multiple times (without calling seek())
* will always return the same image object (or null if there was an error).
*/
sk_sp<SkImage> getFrame();
/**
* Return the size of the image(s) that will be returned by getFrame().
*/
SkISize dimensions() const;
/**
* Returns the total duration of the animation in milliseconds. Returns 0 for a single-frame
* image.
*/
uint32_t duration() const { return fTotalDuration; }
/**
* Finds the closest frame associated with the time code (in milliseconds) and sets that
* to be the current frame (call getFrame() to retrieve that image).
* Returns true iff this call to seek() changed the "current frame" for the animation.
* Thus if seek() returns false, then getFrame() will return the same image as it did
* before this call to seek().
*/
bool seek(uint32_t msec);
private:
std::unique_ptr<SkCodec> fCodec;
SkImageInfo fImageInfo;
std::vector<SkCodec::FrameInfo> fFrameInfos;
std::vector<sk_sp<SkImage> > fImages;
int fCurrIndex = 0;
uint32_t fTotalDuration;
sk_sp<SkImage> getFrameAt(int index);
};
#endif