blob: daaa07f90622e5572e2bd47fea04d4471be7aa61 [file] [log] [blame]
reed43fe6182015-09-08 08:37:36 -07001/*
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 "GrTypes.h"
12#include "SkImageInfo.h"
msarett4984c3c2016-03-10 05:44:43 -080013#include "SkYUVSizeInfo.h"
reed43fe6182015-09-08 08:37:36 -070014
15class GrContext;
Brian Salomonf4a00e42018-03-23 15:15:03 -040016struct GrSurfaceDesc;
reed43fe6182015-09-08 08:37:36 -070017class GrTexture;
Brian Salomonc65aec92017-03-09 09:03:58 -050018class GrTextureProxy;
reed43fe6182015-09-08 08:37:36 -070019
20/**
21 * There are at least 2 different ways to extract/retrieve YUV planar data...
22 * - SkPixelRef
Brian Osmanef90ae42017-04-24 09:30:24 -040023 * - SkImageGenerator
reed43fe6182015-09-08 08:37:36 -070024 *
25 * To share common functionality around using the planar data, we use this abstract base-class
26 * to represent accessing that data.
27 */
28class GrYUVProvider {
29public:
30 virtual ~GrYUVProvider() {}
31
32 /**
Robert Phillips538f1a32017-03-08 14:32:55 -050033 * On success, this returns a texture proxy that has converted the YUV data from the provider
Greg Daniel1445da62018-01-04 10:27:29 -050034 * into a form that is supported by the GPU (typically transformed into RGB). The texture will
35 * automatically have a key added, so it can be retrieved from the cache (assuming it is
36 * requested by a provider w/ the same genID). If srcColorSpace and dstColorSpace are
37 * specified, then a color conversion from src to dst will be applied to the pixels.
reed43fe6182015-09-08 08:37:36 -070038 *
39 * On failure (e.g. the provider had no data), this returns NULL.
40 */
Greg Daniel1445da62018-01-04 10:27:29 -050041 sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*, const GrSurfaceDesc&,
Christopher Cameron77e96662017-07-08 01:47:47 -070042 const SkColorSpace* srcColorSpace,
43 const SkColorSpace* dstColorSpace);
reed43fe6182015-09-08 08:37:36 -070044
45 virtual uint32_t onGetID() = 0;
46
reed43fe6182015-09-08 08:37:36 -070047 // These are not meant to be called by a client, only by the implementation
48
49 /**
msarett4984c3c2016-03-10 05:44:43 -080050 * If decoding to YUV is supported, this returns true. Otherwise, this
51 * returns false and does not modify any of the parameters.
52 *
53 * @param sizeInfo Output parameter indicating the sizes and required
54 * allocation widths of the Y, U, and V planes.
55 * @param colorSpace Output parameter.
reed43fe6182015-09-08 08:37:36 -070056 */
msarett4984c3c2016-03-10 05:44:43 -080057 virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0;
reed43fe6182015-09-08 08:37:36 -070058
59 /**
msarett4984c3c2016-03-10 05:44:43 -080060 * Returns true on success and false on failure.
61 * This always attempts to perform a full decode. If the client only
62 * wants size, it should call onQueryYUV8().
reed43fe6182015-09-08 08:37:36 -070063 *
msarett4984c3c2016-03-10 05:44:43 -080064 * @param sizeInfo Needs to exactly match the values returned by the
65 * query, except the WidthBytes may be larger than the
66 * recommendation (but not smaller).
67 * @param planes Memory for each of the Y, U, and V planes.
reed43fe6182015-09-08 08:37:36 -070068 */
msarett4984c3c2016-03-10 05:44:43 -080069 virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0;
Greg Danielfb3abcd2018-02-02 15:48:33 -050070
71private:
72 // This is used as release callback for the YUV data that we capture in an SkImage when
73 // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
74 // release the underlying data.
75 static void YUVGen_DataReleaseProc(const void*, void* data);
reed43fe6182015-09-08 08:37:36 -070076};
77
78#endif