• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #ifndef YUVUtils_DEFINED
9 #define YUVUtils_DEFINED
10 
11 #include "include/core/SkImage.h"
12 #include "include/core/SkYUVAIndex.h"
13 #include "include/core/SkYUVASizeInfo.h"
14 #include "src/core/SkAutoMalloc.h"
15 
16 class SkData;
17 
18 namespace 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)
24 class LazyYUVImage {
25 public:
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 
33 private:
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 
LazyYUVImage()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
55