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 | |
| 11 | #include "GrTypes.h" |
| 12 | #include "SkImageInfo.h" |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 13 | #include "SkYUVSizeInfo.h" |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 14 | |
| 15 | class GrContext; |
Brian Salomon | f4a00e4 | 2018-03-23 15:15:03 -0400 | [diff] [blame] | 16 | struct GrSurfaceDesc; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 17 | class GrTexture; |
Brian Salomon | c65aec9 | 2017-03-09 09:03:58 -0500 | [diff] [blame] | 18 | class GrTextureProxy; |
Robert Phillips | b4a8eac | 2018-09-21 08:26:33 -0400 | [diff] [blame] | 19 | class SkCachedData; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * There are at least 2 different ways to extract/retrieve YUV planar data... |
| 23 | * - SkPixelRef |
Brian Osman | ef90ae4 | 2017-04-24 09:30:24 -0400 | [diff] [blame] | 24 | * - SkImageGenerator |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 25 | * |
| 26 | * To share common functionality around using the planar data, we use this abstract base-class |
| 27 | * to represent accessing that data. |
| 28 | */ |
| 29 | class GrYUVProvider { |
| 30 | public: |
| 31 | virtual ~GrYUVProvider() {} |
| 32 | |
| 33 | /** |
Robert Phillips | 538f1a3 | 2017-03-08 14:32:55 -0500 | [diff] [blame] | 34 | * 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] | 35 | * into a form that is supported by the GPU (typically transformed into RGB). The texture will |
| 36 | * automatically have a key added, so it can be retrieved from the cache (assuming it is |
| 37 | * requested by a provider w/ the same genID). If srcColorSpace and dstColorSpace are |
| 38 | * 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] | 39 | * |
| 40 | * On failure (e.g. the provider had no data), this returns NULL. |
| 41 | */ |
Greg Daniel | 1445da6 | 2018-01-04 10:27:29 -0500 | [diff] [blame] | 42 | sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*, const GrSurfaceDesc&, |
Brian Osman | 861ea5b | 2018-06-14 09:14:03 -0400 | [diff] [blame] | 43 | SkColorSpace* srcColorSpace, |
| 44 | SkColorSpace* dstColorSpace); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 45 | |
Jim Van Verth | f99a674 | 2018-10-18 16:13:18 +0000 | [diff] [blame] | 46 | sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVColorSpace*, const void* planes[3]); |
Robert Phillips | b4a8eac | 2018-09-21 08:26:33 -0400 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | virtual uint32_t onGetID() const = 0; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 50 | |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 51 | // These are not meant to be called by a client, only by the implementation |
| 52 | |
| 53 | /** |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 54 | * If decoding to YUV is supported, this returns true. Otherwise, this |
| 55 | * returns false and does not modify any of the parameters. |
| 56 | * |
Jim Van Verth | f99a674 | 2018-10-18 16:13:18 +0000 | [diff] [blame] | 57 | * @param sizeInfo Output parameter indicating the sizes and required |
| 58 | * allocation widths of the Y, U, and V planes. |
| 59 | * @param colorSpace Output parameter. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 60 | */ |
Jim Van Verth | f99a674 | 2018-10-18 16:13:18 +0000 | [diff] [blame] | 61 | virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 64 | * Returns true on success and false on failure. |
| 65 | * This always attempts to perform a full decode. If the client only |
Jim Van Verth | f99a674 | 2018-10-18 16:13:18 +0000 | [diff] [blame] | 66 | * wants size, it should call onQueryYUV8(). |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 67 | * |
Jim Van Verth | f99a674 | 2018-10-18 16:13:18 +0000 | [diff] [blame] | 68 | * @param sizeInfo Needs to exactly match the values returned by the |
| 69 | * query, except the WidthBytes may be larger than the |
| 70 | * recommendation (but not smaller). |
| 71 | * @param planes Memory for each of the Y, U, and V planes. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 72 | */ |
Jim Van Verth | f99a674 | 2018-10-18 16:13:18 +0000 | [diff] [blame] | 73 | virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0; |
Greg Daniel | fb3abcd | 2018-02-02 15:48:33 -0500 | [diff] [blame] | 74 | |
Greg Daniel | fb3abcd | 2018-02-02 15:48:33 -0500 | [diff] [blame] | 75 | // This is used as release callback for the YUV data that we capture in an SkImage when |
| 76 | // uploading to a gpu. When the upload is complete and we release the SkImage this callback will |
| 77 | // release the underlying data. |
| 78 | static void YUVGen_DataReleaseProc(const void*, void* data); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | #endif |