SkAnimCodecPlayer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2018 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkAnimCodecPlayer_DEFINED
  8. #define SkAnimCodecPlayer_DEFINED
  9. #include "SkCodec.h"
  10. class SkImage;
  11. class SkAnimCodecPlayer {
  12. public:
  13. SkAnimCodecPlayer(std::unique_ptr<SkCodec> codec);
  14. ~SkAnimCodecPlayer();
  15. /**
  16. * Returns the current frame of the animation. This defaults to the first frame for
  17. * animated codecs (i.e. msec = 0). Calling this multiple times (without calling seek())
  18. * will always return the same image object (or null if there was an error).
  19. */
  20. sk_sp<SkImage> getFrame();
  21. /**
  22. * Return the size of the image(s) that will be returned by getFrame().
  23. */
  24. SkISize dimensions();
  25. /**
  26. * Returns the total duration of the animation in milliseconds. Returns 0 for a single-frame
  27. * image.
  28. */
  29. uint32_t duration() { return fTotalDuration; }
  30. /**
  31. * Finds the closest frame associated with the time code (in milliseconds) and sets that
  32. * to be the current frame (call getFrame() to retrieve that image).
  33. * Returns true iff this call to seek() changed the "current frame" for the animation.
  34. * Thus if seek() returns false, then getFrame() will return the same image as it did
  35. * before this call to seek().
  36. */
  37. bool seek(uint32_t msec);
  38. private:
  39. std::unique_ptr<SkCodec> fCodec;
  40. SkImageInfo fImageInfo;
  41. std::vector<SkCodec::FrameInfo> fFrameInfos;
  42. std::vector<sk_sp<SkImage> > fImages;
  43. int fCurrIndex = 0;
  44. uint32_t fTotalDuration;
  45. sk_sp<SkImage> getFrameAt(int index);
  46. };
  47. #endif