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; |
| 16 | class GrTexture; |
| 17 | |
| 18 | /** |
| 19 | * There are at least 2 different ways to extract/retrieve YUV planar data... |
| 20 | * - SkPixelRef |
| 21 | * - SkImageGeneartor |
| 22 | * |
| 23 | * To share common functionality around using the planar data, we use this abstract base-class |
| 24 | * to represent accessing that data. |
| 25 | */ |
| 26 | class GrYUVProvider { |
| 27 | public: |
| 28 | virtual ~GrYUVProvider() {} |
| 29 | |
| 30 | /** |
| 31 | * On success, this returns a texture that has converted the YUV data from the provider |
| 32 | * into a form that is supported by the GPU (typically transformed into RGB). If useCache |
| 33 | * is true, then the texture will automatically have a key added, so it can be retrieved |
| 34 | * from the cache (assuming it is requested by a provider w/ the same genID). |
| 35 | * |
| 36 | * On failure (e.g. the provider had no data), this returns NULL. |
| 37 | */ |
robertphillips | 677da9d | 2016-05-11 05:15:55 -0700 | [diff] [blame] | 38 | sk_sp<GrTexture> refAsTexture(GrContext*, const GrSurfaceDesc&, bool useCache); |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 39 | |
| 40 | virtual uint32_t onGetID() = 0; |
| 41 | |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 42 | // These are not meant to be called by a client, only by the implementation |
| 43 | |
| 44 | /** |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 45 | * If decoding to YUV is supported, this returns true. Otherwise, this |
| 46 | * returns false and does not modify any of the parameters. |
| 47 | * |
| 48 | * @param sizeInfo Output parameter indicating the sizes and required |
| 49 | * allocation widths of the Y, U, and V planes. |
| 50 | * @param colorSpace Output parameter. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 51 | */ |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 52 | virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 55 | * Returns true on success and false on failure. |
| 56 | * This always attempts to perform a full decode. If the client only |
| 57 | * wants size, it should call onQueryYUV8(). |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 58 | * |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 59 | * @param sizeInfo Needs to exactly match the values returned by the |
| 60 | * query, except the WidthBytes may be larger than the |
| 61 | * recommendation (but not smaller). |
| 62 | * @param planes Memory for each of the Y, U, and V planes. |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 63 | */ |
msarett | 4984c3c | 2016-03-10 05:44:43 -0800 | [diff] [blame] | 64 | virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0; |
reed | 43fe618 | 2015-09-08 08:37:36 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif |