YUVUtils.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright 2019 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 YUVUtils_DEFINED
  8. #define YUVUtils_DEFINED
  9. #include "include/core/SkImage.h"
  10. #include "include/core/SkYUVAIndex.h"
  11. #include "include/core/SkYUVASizeInfo.h"
  12. #include "src/core/SkAutoMalloc.h"
  13. class SkData;
  14. namespace sk_gpu_test {
  15. // Utility that decodes a JPEG but preserves the YUVA8 planes in the image, and uses
  16. // MakeFromYUVAPixmaps to create a GPU multiplane YUVA image for a context. It extracts the planar
  17. // data once, and lazily creates the actual SkImage when the GrContext is provided (and refreshes
  18. // the image if the context has changed, as in Viewer)
  19. class LazyYUVImage {
  20. public:
  21. // Returns null if the data could not be extracted into YUVA8 planes
  22. static std::unique_ptr<LazyYUVImage> Make(sk_sp<SkData> data);
  23. sk_sp<SkImage> refImage(GrContext* context);
  24. const SkImage* getImage(GrContext* context);
  25. private:
  26. // Decoded YUV data
  27. SkYUVASizeInfo fSizeInfo;
  28. SkYUVColorSpace fColorSpace;
  29. SkYUVAIndex fComponents[SkYUVAIndex::kIndexCount];
  30. SkAutoMalloc fPlaneData;
  31. SkPixmap fPlanes[SkYUVASizeInfo::kMaxCount];
  32. // Memoized SkImage formed with planes
  33. sk_sp<SkImage> fYUVImage;
  34. uint32_t fOwningContextID;
  35. LazyYUVImage() : fOwningContextID(SK_InvalidGenID) {}
  36. bool reset(sk_sp<SkData> data);
  37. bool ensureYUVImage(GrContext* context);
  38. };
  39. } // namespace sk_gpu_test
  40. #endif // YUVUtils_DEFINED