reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 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 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 11 | #include <include/private/GrTypesPriv.h> |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkImageInfo.h" |
| 13 | #include "include/core/SkYUVAIndex.h" |
| 14 | #include "include/core/SkYUVASizeInfo.h" |
| 15 | #include "include/gpu/GrTypes.h" |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 16 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 17 | class GrBackendFormat; |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 18 | class GrRecordingContext; |
Brian Salomon | f4a00e4 | 2018-03-23 15:15:03 -0400 | [diff] [blame] | 19 | struct GrSurfaceDesc; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 20 | class GrTexture; |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 21 | class GrTextureProxy; |
Robert Phillips | b4a8eac | 2018-09-21 08:26:33 -0400 | [diff] [blame] | 22 | class SkCachedData; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * There are at least 2 different ways to extract/retrieve YUV planar data... |
| 26 | * - SkPixelRef |
Brian Osman | ef90ae4 | 2017-04-24 09:30:24 -0400 | [diff] [blame] | 27 | * - SkImageGenerator |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 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: |
| 34 | virtual ~GrYUVProvider() {} |
| 35 | |
| 36 | /** |
Robert Phillips | 538f1a3 | 2017-03-08 14:32:55 -0500 | [diff] [blame] | 37 | * On success, this returns a texture proxy that has converted the YUV data from the provider |
Greg Daniel | 1445da6 | 2018-01-04 10:27:29 -0500 | [diff] [blame] | 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. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 42 | * |
| 43 | * On failure (e.g. the provider had no data), this returns NULL. |
| 44 | */ |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 45 | sk_sp<GrTextureProxy> refAsTextureProxy(GrRecordingContext*, |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 46 | const GrBackendFormat&, |
| 47 | const GrSurfaceDesc&, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 48 | GrColorType colorType, |
Brian Osman | 861ea5b | 2018-06-14 09:14:03 -0400 | [diff] [blame] | 49 | SkColorSpace* srcColorSpace, |
| 50 | SkColorSpace* dstColorSpace); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 51 | |
Jim Van Verth | e24b587 | 2018-10-29 16:26:02 -0400 | [diff] [blame] | 52 | sk_sp<SkCachedData> getPlanes(SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount], |
| 53 | SkYUVColorSpace*, const void* planes[SkYUVASizeInfo::kMaxCount]); |
Robert Phillips | b4a8eac | 2018-09-21 08:26:33 -0400 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | virtual uint32_t onGetID() const = 0; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 57 | |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 58 | // These are not meant to be called by a client, only by the implementation |
| 59 | |
| 60 | /** |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 61 | * 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 Verth | 8f11e43 | 2018-10-18 14:36:59 -0400 | [diff] [blame] | 64 | * @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. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 68 | */ |
Jim Van Verth | e24b587 | 2018-10-29 16:26:02 -0400 | [diff] [blame] | 69 | virtual bool onQueryYUVA8(SkYUVASizeInfo* sizeInfo, |
Jim Van Verth | 8f11e43 | 2018-10-18 14:36:59 -0400 | [diff] [blame] | 70 | SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount], |
| 71 | SkYUVColorSpace* colorSpace) const = 0; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 74 | * Returns true on success and false on failure. |
| 75 | * This always attempts to perform a full decode. If the client only |
Jim Van Verth | 8f11e43 | 2018-10-18 14:36:59 -0400 | [diff] [blame] | 76 | * wants size, it should call onQueryYUVA8(). |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 77 | * |
Jim Van Verth | 8f11e43 | 2018-10-18 14:36:59 -0400 | [diff] [blame] | 78 | * @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. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 83 | */ |
Jim Van Verth | e24b587 | 2018-10-29 16:26:02 -0400 | [diff] [blame] | 84 | virtual bool onGetYUVA8Planes(const SkYUVASizeInfo& sizeInfo, |
Jim Van Verth | 8f11e43 | 2018-10-18 14:36:59 -0400 | [diff] [blame] | 85 | const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount], |
| 86 | void* planes[]) = 0; |
Greg Daniel | fb3abcd | 2018-02-02 15:48:33 -0500 | [diff] [blame] | 87 | |
Greg Daniel | fb3abcd | 2018-02-02 15:48:33 -0500 | [diff] [blame] | 88 | // 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); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #endif |