blob: f6097b9476d02c97bba48d31250c2686e7476527 [file] [log] [blame]
Michael Ludwigd9958f82019-03-21 13:08:36 -04001/*
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
8#ifndef YUVUtils_DEFINED
9#define YUVUtils_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkImage.h"
12#include "include/core/SkYUVAIndex.h"
13#include "include/core/SkYUVASizeInfo.h"
14#include "src/core/SkAutoMalloc.h"
Michael Ludwigd9958f82019-03-21 13:08:36 -040015
16class SkData;
17
18namespace sk_gpu_test {
19
20// Utility that decodes a JPEG but preserves the YUVA8 planes in the image, and uses
21// MakeFromYUVAPixmaps to create a GPU multiplane YUVA image for a context. It extracts the planar
22// data once, and lazily creates the actual SkImage when the GrContext is provided (and refreshes
23// the image if the context has changed, as in Viewer)
24class LazyYUVImage {
25public:
26 // Returns null if the data could not be extracted into YUVA8 planes
27 static std::unique_ptr<LazyYUVImage> Make(sk_sp<SkData> data);
28
29 sk_sp<SkImage> refImage(GrContext* context);
30
31 const SkImage* getImage(GrContext* context);
32
33private:
34 // Decoded YUV data
35 SkYUVASizeInfo fSizeInfo;
36 SkYUVColorSpace fColorSpace;
37 SkYUVAIndex fComponents[SkYUVAIndex::kIndexCount];
38 SkAutoMalloc fPlaneData;
39 SkPixmap fPlanes[SkYUVASizeInfo::kMaxCount];
40
41 // Memoized SkImage formed with planes
42 sk_sp<SkImage> fYUVImage;
43 uint32_t fOwningContextID;
44
45 LazyYUVImage() : fOwningContextID(SK_InvalidGenID) {}
46
47 bool reset(sk_sp<SkData> data);
48
49 bool ensureYUVImage(GrContext* context);
50};
51
52} // namespace sk_gpu_test
53
54#endif // YUVUtils_DEFINED