blob: 04abdb5ebc0080cef967e8e490fb3818a624da16 [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
Brian Salomond6287472019-06-24 15:50:07 -040011#include <include/private/GrTypesPriv.h>
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkImageInfo.h"
13#include "include/core/SkYUVAIndex.h"
14#include "include/core/SkYUVASizeInfo.h"
15#include "include/gpu/GrTypes.h"
reed43fe6182015-09-08 08:37:36 -070016
Greg Daniel4065d452018-11-16 15:43:41 -050017class GrBackendFormat;
Robert Phillips9338c602019-02-19 12:52:29 -050018class GrRecordingContext;
Brian Salomonf4a00e42018-03-23 15:15:03 -040019struct GrSurfaceDesc;
reed43fe6182015-09-08 08:37:36 -070020class GrTexture;
Brian Salomonc65aec92017-03-09 09:03:58 -050021class GrTextureProxy;
Robert Phillipsb4a8eac2018-09-21 08:26:33 -040022class SkCachedData;
reed43fe6182015-09-08 08:37:36 -070023
24/**
25 * There are at least 2 different ways to extract/retrieve YUV planar data...
26 * - SkPixelRef
Brian Osmanef90ae42017-04-24 09:30:24 -040027 * - SkImageGenerator
reed43fe6182015-09-08 08:37:36 -070028 *
29 * To share common functionality around using the planar data, we use this abstract base-class
30 * to represent accessing that data.
31 */
32class GrYUVProvider {
33public:
34 virtual ~GrYUVProvider() {}
35
36 /**
Robert Phillips538f1a32017-03-08 14:32:55 -050037 * On success, this returns a texture proxy that has converted the YUV data from the provider
Greg Daniel1445da62018-01-04 10:27:29 -050038 * 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.
reed43fe6182015-09-08 08:37:36 -070042 *
43 * On failure (e.g. the provider had no data), this returns NULL.
44 */
Robert Phillips9338c602019-02-19 12:52:29 -050045 sk_sp<GrTextureProxy> refAsTextureProxy(GrRecordingContext*,
Greg Daniel4065d452018-11-16 15:43:41 -050046 const GrBackendFormat&,
47 const GrSurfaceDesc&,
Brian Salomond6287472019-06-24 15:50:07 -040048 GrColorType colorType,
Brian Osman861ea5b2018-06-14 09:14:03 -040049 SkColorSpace* srcColorSpace,
50 SkColorSpace* dstColorSpace);
reed43fe6182015-09-08 08:37:36 -070051
Jim Van Verthe24b5872018-10-29 16:26:02 -040052 sk_sp<SkCachedData> getPlanes(SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount],
53 SkYUVColorSpace*, const void* planes[SkYUVASizeInfo::kMaxCount]);
Robert Phillipsb4a8eac2018-09-21 08:26:33 -040054
55private:
56 virtual uint32_t onGetID() const = 0;
reed43fe6182015-09-08 08:37:36 -070057
reed43fe6182015-09-08 08:37:36 -070058 // These are not meant to be called by a client, only by the implementation
59
60 /**
msarett4984c3c2016-03-10 05:44:43 -080061 * If decoding to YUV is supported, this returns true. Otherwise, this
62 * returns false and does not modify any of the parameters.
63 *
Jim Van Verth8f11e432018-10-18 14:36:59 -040064 * @param sizeInfo Output parameter indicating the sizes and required
65 * allocation widths of the Y, U, V, and A planes.
66 * @param yuvaIndices How the YUVA planes are used/organized
67 * @param colorSpace Output parameter.
reed43fe6182015-09-08 08:37:36 -070068 */
Jim Van Verthe24b5872018-10-29 16:26:02 -040069 virtual bool onQueryYUVA8(SkYUVASizeInfo* sizeInfo,
Jim Van Verth8f11e432018-10-18 14:36:59 -040070 SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
71 SkYUVColorSpace* colorSpace) const = 0;
reed43fe6182015-09-08 08:37:36 -070072
73 /**
msarett4984c3c2016-03-10 05:44:43 -080074 * Returns true on success and false on failure.
75 * This always attempts to perform a full decode. If the client only
Jim Van Verth8f11e432018-10-18 14:36:59 -040076 * wants size, it should call onQueryYUVA8().
reed43fe6182015-09-08 08:37:36 -070077 *
Jim Van Verth8f11e432018-10-18 14:36:59 -040078 * @param sizeInfo Needs to exactly match the values returned by the
79 * query, except the WidthBytes may be larger than the
80 * recommendation (but not smaller).
81 * @param yuvaIndices How the YUVA planes are used/organized
82 * @param planes Memory for each of the Y, U, V, and A planes.
reed43fe6182015-09-08 08:37:36 -070083 */
Jim Van Verthe24b5872018-10-29 16:26:02 -040084 virtual bool onGetYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
Jim Van Verth8f11e432018-10-18 14:36:59 -040085 const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
86 void* planes[]) = 0;
Greg Danielfb3abcd2018-02-02 15:48:33 -050087
Greg Danielfb3abcd2018-02-02 15:48:33 -050088 // This is used as release callback for the YUV data that we capture in an SkImage when
89 // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
90 // release the underlying data.
91 static void YUVGen_DataReleaseProc(const void*, void* data);
reed43fe6182015-09-08 08:37:36 -070092};
93
94#endif