be0e42cb8f
SkYUVAPixmapInfo is a SkYUVAInfo with per-plane color types and row bytes. It describes a set of pixmaps that make up a planar image. Consolidates validity checks of the SkYUVAInfo with the color types and row bytes. It can provide SkImageInfos for each plane and also assist with configuring planes to share a common allocation. SkYUVAPixmaps is a collection of SkPixmaps that are valid for a SkYUVAInfo. It can either wrap existing SkPixmaps or allocate and own the memory. It consolidates validity checking of SkPixmaps with the SkYUVAInfo. Replaces sk_gpu_test::YUVAPixmaps. Minor tweaks to SkYUVAInfo naming, parameter order consistency, adds a hasAlpha() method. Bug: skia:10632 Change-Id: Ib0f48b8448fff22805fd0c04e07887d0b7338b76 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312886 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com>
118 lines
3.4 KiB
C++
118 lines
3.4 KiB
C++
/*
|
|
* 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
|
|
|
|
#include "include/core/SkImage.h"
|
|
#include "include/core/SkYUVAIndex.h"
|
|
#include "include/core/SkYUVAPixmaps.h"
|
|
#include "include/core/SkYUVASizeInfo.h"
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
#include "src/core/SkAutoMalloc.h"
|
|
|
|
class SkData;
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
// 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:
|
|
// Returns null if the data could not be extracted into YUVA8 planes
|
|
static std::unique_ptr<LazyYUVImage> Make(sk_sp<SkData> data, GrMipmapped = GrMipmapped::kNo);
|
|
|
|
sk_sp<SkImage> refImage(GrRecordingContext* rContext);
|
|
|
|
const SkImage* getImage(GrRecordingContext* rContext);
|
|
|
|
private:
|
|
// Decoded YUV data
|
|
SkYUVAPixmaps fPixmaps;
|
|
|
|
// Legacy representation used to import to SkImage.
|
|
SkYUVASizeInfo fSizeInfo;
|
|
SkYUVAIndex fComponents[SkYUVAIndex::kIndexCount];
|
|
|
|
GrMipmapped fMipmapped;
|
|
|
|
// Memoized SkImage formed with planes
|
|
sk_sp<SkImage> fYUVImage;
|
|
|
|
LazyYUVImage() = default;
|
|
|
|
bool reset(sk_sp<SkData> data, GrMipmapped);
|
|
|
|
bool ensureYUVImage(GrRecordingContext* rContext);
|
|
};
|
|
|
|
// A helper for managing the lifetime of backend textures for YUVA images.
|
|
class YUVABackendReleaseContext {
|
|
public:
|
|
static GrGpuFinishedProc CreationCompleteProc(int index);
|
|
|
|
// A stock 'TextureReleaseProc' to use with this class
|
|
static void Release(void* releaseContext) {
|
|
auto beContext = reinterpret_cast<YUVABackendReleaseContext*>(releaseContext);
|
|
|
|
delete beContext;
|
|
}
|
|
|
|
// Given how and when backend textures are created, just deleting this object often
|
|
// isn't enough. This helper encapsulates the extra work needed.
|
|
static void Unwind(GrDirectContext*, YUVABackendReleaseContext* beContext, bool fullFlush);
|
|
|
|
YUVABackendReleaseContext(GrDirectContext*);
|
|
~YUVABackendReleaseContext();
|
|
|
|
void set(int index, const GrBackendTexture& beTex) {
|
|
SkASSERT(index >= 0 && index < 4);
|
|
SkASSERT(!fBETextures[index].isValid());
|
|
SkASSERT(beTex.isValid());
|
|
|
|
fBETextures[index] = beTex;
|
|
}
|
|
|
|
void setCreationComplete(int index) {
|
|
SkASSERT(index >= 0 && index < 4);
|
|
// In GL, the finished proc can fire before the backend texture is returned to the client
|
|
// SkASSERT(fBETextures[index].isValid());
|
|
|
|
fCreationComplete[index] = true;
|
|
}
|
|
|
|
bool creationCompleted() const {
|
|
for (int i = 0; i < 4; ++i) {
|
|
if (fBETextures[i].isValid() && !fCreationComplete[i]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
const GrBackendTexture* beTextures() const { return fBETextures; }
|
|
|
|
const GrBackendTexture& beTexture(int index) {
|
|
SkASSERT(index >= 0 && index < 4);
|
|
SkASSERT(fBETextures[index].isValid());
|
|
return fBETextures[index];
|
|
}
|
|
|
|
private:
|
|
GrDirectContext* fDContext;
|
|
GrBackendTexture fBETextures[4];
|
|
bool fCreationComplete[4] = { false };
|
|
};
|
|
|
|
|
|
} // namespace sk_gpu_test
|
|
|
|
#endif // YUVUtils_DEFINED
|