• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 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 GrYUVProvider_DEFINED
9 #define GrYUVProvider_DEFINED
10 
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkYUVAIndex.h"
13 #include "include/core/SkYUVASizeInfo.h"
14 #include "include/gpu/GrTypes.h"
15 #include "include/private/GrTypesPriv.h"
16 
17 class GrBackendFormat;
18 class GrRecordingContext;
19 struct GrSurfaceDesc;
20 class GrTexture;
21 class GrTextureProxy;
22 class SkCachedData;
23 
24 /**
25  *  There are at least 2 different ways to extract/retrieve YUV planar data...
26  *  - SkPixelRef
27  *  - SkImageGenerator
28  *
29  *  To share common functionality around using the planar data, we use this abstract base-class
30  *  to represent accessing that data.
31  */
32 class GrYUVProvider {
33 public:
~GrYUVProvider()34     virtual ~GrYUVProvider() {}
35 
36     /**
37      *  On success, this returns a texture proxy that has converted the YUV data from the provider
38      *  into a form that is supported by the GPU (typically transformed into RGB). The texture will
39      *  automatically have a key added, so it can be retrieved from the cache (assuming it is
40      *  requested by a provider w/ the same genID). If srcColorSpace and dstColorSpace are
41      *  specified, then a color conversion from src to dst will be applied to the pixels.
42      *
43      *  On failure (e.g. the provider had no data), this returns NULL.
44      */
45     sk_sp<GrTextureProxy> refAsTextureProxy(GrRecordingContext*,
46                                             const GrSurfaceDesc&,
47                                             GrColorType colorType,
48                                             SkColorSpace* srcColorSpace,
49                                             SkColorSpace* dstColorSpace);
50 
51     sk_sp<SkCachedData> getPlanes(SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount],
52                                   SkYUVColorSpace*, const void* planes[SkYUVASizeInfo::kMaxCount]);
53 
54 private:
55     virtual uint32_t onGetID() const = 0;
56 
57     // These are not meant to be called by a client, only by the implementation
58 
59     /**
60      *  If decoding to YUV is supported, this returns true.  Otherwise, this
61      *  returns false and does not modify any of the parameters.
62      *
63      *  @param sizeInfo    Output parameter indicating the sizes and required
64      *                     allocation widths of the Y, U, V, and A planes.
65      *  @param yuvaIndices How the YUVA planes are used/organized
66      *  @param colorSpace  Output parameter.
67      */
68     virtual bool onQueryYUVA8(SkYUVASizeInfo* sizeInfo,
69                               SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
70                               SkYUVColorSpace* colorSpace) const = 0;
71 
72     /**
73      *  Returns true on success and false on failure.
74      *  This always attempts to perform a full decode.  If the client only
75      *  wants size, it should call onQueryYUVA8().
76      *
77      *  @param sizeInfo    Needs to exactly match the values returned by the
78      *                     query, except the WidthBytes may be larger than the
79      *                     recommendation (but not smaller).
80      *  @param yuvaIndices How the YUVA planes are used/organized
81      *  @param planes      Memory for each of the Y, U, V, and A planes.
82      */
83     virtual bool onGetYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
84                                   const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
85                                   void* planes[]) = 0;
86 
87     // This is used as release callback for the YUV data that we capture in an SkImage when
88     // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
89     // release the underlying data.
90     static void YUVGen_DataReleaseProc(const void*, void* data);
91 };
92 
93 #endif
94