2019-03-21 17:08:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef YUVUtils_DEFINED
|
|
|
|
#define YUVUtils_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2020-08-27 15:00:04 +00:00
|
|
|
#include "include/core/SkYUVAPixmaps.h"
|
2020-06-19 18:27:14 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkAutoMalloc.h"
|
2019-03-21 17:08:36 +00:00
|
|
|
|
2021-05-21 18:00:44 +00:00
|
|
|
#include <tuple>
|
|
|
|
|
2019-03-21 17:08:36 +00:00
|
|
|
class SkData;
|
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2021-05-21 18:00:44 +00:00
|
|
|
// Splits an input image into A8 YUV[A] planes using the passed subsampling and YUV color space. If
|
|
|
|
// the src image is opaque there will be three planes (Y, U, and V) and if not there will be a
|
|
|
|
// fourth A plane. The planes are returned along with a SkYUVAInfo describing the resulting planar
|
|
|
|
// image. Images are made as textures if GrRecordingContext is not null, otherwise as cpu images.
|
|
|
|
std::tuple<std::array<sk_sp<SkImage>, SkYUVAInfo::kMaxPlanes>, SkYUVAInfo>
|
|
|
|
MakeYUVAPlanesAsA8(SkImage*,
|
|
|
|
SkYUVColorSpace,
|
|
|
|
SkYUVAInfo::Subsampling,
|
|
|
|
GrRecordingContext*);
|
|
|
|
|
2019-03-21 17:08:36 +00:00
|
|
|
// Utility that decodes a JPEG but preserves the YUVA8 planes in the image, and uses
|
|
|
|
// MakeFromYUVAPixmaps to create a GPU multiplane YUVA image for a context. It extracts the planar
|
|
|
|
// data once, and lazily creates the actual SkImage when the GrContext is provided (and refreshes
|
|
|
|
// the image if the context has changed, as in Viewer)
|
|
|
|
class LazyYUVImage {
|
|
|
|
public:
|
2020-10-16 14:05:21 +00:00
|
|
|
// Returns null if the data could not be extracted into YUVA planes
|
|
|
|
static std::unique_ptr<LazyYUVImage> Make(sk_sp<SkData> data,
|
|
|
|
GrMipmapped = GrMipmapped::kNo,
|
|
|
|
sk_sp<SkColorSpace> = nullptr);
|
|
|
|
static std::unique_ptr<LazyYUVImage> Make(SkYUVAPixmaps,
|
|
|
|
GrMipmapped = GrMipmapped::kNo,
|
|
|
|
sk_sp<SkColorSpace> = nullptr);
|
2019-03-21 17:08:36 +00:00
|
|
|
|
2020-12-08 21:39:32 +00:00
|
|
|
enum class Type { kFromPixmaps, kFromGenerator, kFromTextures };
|
2019-03-21 17:08:36 +00:00
|
|
|
|
2020-10-16 14:05:21 +00:00
|
|
|
SkISize dimensions() const { return fPixmaps.yuvaInfo().dimensions(); }
|
|
|
|
|
|
|
|
sk_sp<SkImage> refImage(GrRecordingContext* rContext, Type);
|
2019-03-21 17:08:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Decoded YUV data
|
2020-08-27 15:00:04 +00:00
|
|
|
SkYUVAPixmaps fPixmaps;
|
2020-08-24 13:18:16 +00:00
|
|
|
|
2020-10-16 13:30:54 +00:00
|
|
|
GrMipmapped fMipmapped;
|
2020-06-19 18:27:14 +00:00
|
|
|
|
2020-10-16 14:05:21 +00:00
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
2020-10-16 13:30:54 +00:00
|
|
|
|
2020-10-16 14:05:21 +00:00
|
|
|
// Memoized SkImages formed with planes, one for each Type.
|
2020-11-04 21:54:28 +00:00
|
|
|
sk_sp<SkImage> fYUVImage[4];
|
2020-10-16 13:30:54 +00:00
|
|
|
|
2020-10-16 14:05:21 +00:00
|
|
|
LazyYUVImage() = default;
|
2020-10-16 13:30:54 +00:00
|
|
|
|
2020-10-16 14:05:21 +00:00
|
|
|
bool reset(sk_sp<SkData> data, GrMipmapped, sk_sp<SkColorSpace>);
|
|
|
|
bool reset(SkYUVAPixmaps pixmaps, GrMipmapped, sk_sp<SkColorSpace>);
|
2020-10-16 13:30:54 +00:00
|
|
|
|
2020-10-16 14:05:21 +00:00
|
|
|
bool ensureYUVImage(GrRecordingContext* rContext, Type type);
|
2020-10-16 13:30:54 +00:00
|
|
|
};
|
|
|
|
|
2019-03-21 17:08:36 +00:00
|
|
|
} // namespace sk_gpu_test
|
|
|
|
|
|
|
|
#endif // YUVUtils_DEFINED
|