blob: 633ccfb78e0b75d79abd9def0516918eeea1909c [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"
Jim Van Verthe24b5872018-10-29 16:26:02 -040013#include "SkYUVAIndex.h"
14#include "SkYUVASizeInfo.h"
reed43fe6182015-09-08 08:37:36 -070015
16class GrContext;
Greg Daniel4065d452018-11-16 15:43:41 -050017class GrBackendFormat;
Brian Salomonf4a00e42018-03-23 15:15:03 -040018struct GrSurfaceDesc;
reed43fe6182015-09-08 08:37:36 -070019class GrTexture;
Brian Salomonc65aec92017-03-09 09:03:58 -050020class GrTextureProxy;
Robert Phillipsb4a8eac2018-09-21 08:26:33 -040021class SkCachedData;
reed43fe6182015-09-08 08:37:36 -070022
23/**
24 * There are at least 2 different ways to extract/retrieve YUV planar data...
25 * - SkPixelRef
Brian Osmanef90ae42017-04-24 09:30:24 -040026 * - SkImageGenerator
reed43fe6182015-09-08 08:37:36 -070027 *
28 * To share common functionality around using the planar data, we use this abstract base-class
29 * to represent accessing that data.
30 */
31class GrYUVProvider {
32public:
33 virtual ~GrYUVProvider() {}
34
35 /**
Robert Phillips538f1a32017-03-08 14:32:55 -050036 * On success, this returns a texture proxy that has converted the YUV data from the provider
Greg Daniel1445da62018-01-04 10:27:29 -050037 * into a form that is supported by the GPU (typically transformed into RGB). The texture will
38 * automatically have a key added, so it can be retrieved from the cache (assuming it is
39 * requested by a provider w/ the same genID). If srcColorSpace and dstColorSpace are
40 * specified, then a color conversion from src to dst will be applied to the pixels.
reed43fe6182015-09-08 08:37:36 -070041 *
42 * On failure (e.g. the provider had no data), this returns NULL.
43 */
Greg Daniel4065d452018-11-16 15:43:41 -050044 sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*,
45 const GrBackendFormat&,
46 const GrSurfaceDesc&,
Brian Osman861ea5b2018-06-14 09:14:03 -040047 SkColorSpace* srcColorSpace,
48 SkColorSpace* dstColorSpace);
reed43fe6182015-09-08 08:37:36 -070049
Jim Van Verthe24b5872018-10-29 16:26:02 -040050 sk_sp<SkCachedData> getPlanes(SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount],
51 SkYUVColorSpace*, const void* planes[SkYUVASizeInfo::kMaxCount]);
Robert Phillipsb4a8eac2018-09-21 08:26:33 -040052
53private:
54 virtual uint32_t onGetID() const = 0;
reed43fe6182015-09-08 08:37:36 -070055
reed43fe6182015-09-08 08:37:36 -070056 // These are not meant to be called by a client, only by the implementation
57
58 /**
msarett4984c3c2016-03-10 05:44:43 -080059 * If decoding to YUV is supported, this returns true. Otherwise, this
60 * returns false and does not modify any of the parameters.
61 *
Jim Van Verth8f11e432018-10-18 14:36:59 -040062 * @param sizeInfo Output parameter indicating the sizes and required
63 * allocation widths of the Y, U, V, and A planes.
64 * @param yuvaIndices How the YUVA planes are used/organized
65 * @param colorSpace Output parameter.
reed43fe6182015-09-08 08:37:36 -070066 */
Jim Van Verthe24b5872018-10-29 16:26:02 -040067 virtual bool onQueryYUVA8(SkYUVASizeInfo* sizeInfo,
Jim Van Verth8f11e432018-10-18 14:36:59 -040068 SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
69 SkYUVColorSpace* colorSpace) const = 0;
reed43fe6182015-09-08 08:37:36 -070070
71 /**
msarett4984c3c2016-03-10 05:44:43 -080072 * Returns true on success and false on failure.
73 * This always attempts to perform a full decode. If the client only
Jim Van Verth8f11e432018-10-18 14:36:59 -040074 * wants size, it should call onQueryYUVA8().
reed43fe6182015-09-08 08:37:36 -070075 *
Jim Van Verth8f11e432018-10-18 14:36:59 -040076 * @param sizeInfo Needs to exactly match the values returned by the
77 * query, except the WidthBytes may be larger than the
78 * recommendation (but not smaller).
79 * @param yuvaIndices How the YUVA planes are used/organized
80 * @param planes Memory for each of the Y, U, V, and A planes.
reed43fe6182015-09-08 08:37:36 -070081 */
Jim Van Verthe24b5872018-10-29 16:26:02 -040082 virtual bool onGetYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
Jim Van Verth8f11e432018-10-18 14:36:59 -040083 const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
84 void* planes[]) = 0;
Greg Danielfb3abcd2018-02-02 15:48:33 -050085
Greg Danielfb3abcd2018-02-02 15:48:33 -050086 // This is used as release callback for the YUV data that we capture in an SkImage when
87 // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
88 // release the underlying data.
89 static void YUVGen_DataReleaseProc(const void*, void* data);
reed43fe6182015-09-08 08:37:36 -070090};
91
92#endif