blob: b5be426f6d04f7c4d147073c3c0cda94a0a20eaf [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"
msarett4984c3c2016-03-10 05:44:43 -080013#include "SkYUVSizeInfo.h"
reed43fe6182015-09-08 08:37:36 -070014
15class GrContext;
16class GrTexture;
Brian Salomonc65aec92017-03-09 09:03:58 -050017class GrTextureProxy;
reed43fe6182015-09-08 08:37:36 -070018
19/**
20 * There are at least 2 different ways to extract/retrieve YUV planar data...
21 * - SkPixelRef
Brian Osmanef90ae42017-04-24 09:30:24 -040022 * - SkImageGenerator
reed43fe6182015-09-08 08:37:36 -070023 *
24 * To share common functionality around using the planar data, we use this abstract base-class
25 * to represent accessing that data.
26 */
27class GrYUVProvider {
28public:
29 virtual ~GrYUVProvider() {}
30
31 /**
Robert Phillips538f1a32017-03-08 14:32:55 -050032 * On success, this returns a texture proxy that has converted the YUV data from the provider
reed43fe6182015-09-08 08:37:36 -070033 * into a form that is supported by the GPU (typically transformed into RGB). If useCache
34 * is true, then the texture will automatically have a key added, so it can be retrieved
35 * from the cache (assuming it is requested by a provider w/ the same genID).
36 *
37 * On failure (e.g. the provider had no data), this returns NULL.
38 */
Robert Phillips538f1a32017-03-08 14:32:55 -050039 sk_sp<GrTextureProxy> refAsTextureProxy(GrContext*, const GrSurfaceDesc&, bool useCache);
reed43fe6182015-09-08 08:37:36 -070040
41 virtual uint32_t onGetID() = 0;
42
reed43fe6182015-09-08 08:37:36 -070043 // These are not meant to be called by a client, only by the implementation
44
45 /**
msarett4984c3c2016-03-10 05:44:43 -080046 * If decoding to YUV is supported, this returns true. Otherwise, this
47 * returns false and does not modify any of the parameters.
48 *
49 * @param sizeInfo Output parameter indicating the sizes and required
50 * allocation widths of the Y, U, and V planes.
51 * @param colorSpace Output parameter.
reed43fe6182015-09-08 08:37:36 -070052 */
msarett4984c3c2016-03-10 05:44:43 -080053 virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0;
reed43fe6182015-09-08 08:37:36 -070054
55 /**
msarett4984c3c2016-03-10 05:44:43 -080056 * Returns true on success and false on failure.
57 * This always attempts to perform a full decode. If the client only
58 * wants size, it should call onQueryYUV8().
reed43fe6182015-09-08 08:37:36 -070059 *
msarett4984c3c2016-03-10 05:44:43 -080060 * @param sizeInfo Needs to exactly match the values returned by the
61 * query, except the WidthBytes may be larger than the
62 * recommendation (but not smaller).
63 * @param planes Memory for each of the Y, U, and V planes.
reed43fe6182015-09-08 08:37:36 -070064 */
msarett4984c3c2016-03-10 05:44:43 -080065 virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0;
reed43fe6182015-09-08 08:37:36 -070066};
67
68#endif