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 SkYUVPlanesCache_DEFINED
9#define SkYUVPlanesCache_DEFINED
10
11#include "SkCachedData.h"
12#include "SkImageInfo.h"
13
14class SkResourceCache;
15
16class SkYUVPlanesCache {
17public:
18    /**
19     * The Info struct contains data about the 3 Y, U and V planes of memory stored
20     * contiguously, in that order, as a single block of memory within SkYUVPlanesCache.
21     *
22     * fSize: Width and height of each of the 3 planes (in pixels).
23     * fSizeInMemory: Amount of memory allocated for each plane (may be different from
24                      "height * rowBytes", depending on the jpeg decoder's block size).
25     *                The sum of these is the total size stored within SkYUVPlanesCache.
26     * fRowBytes: rowBytes for each of the 3 planes (in bytes).
27     * fColorSpace: color space that will be used for the YUV -> RGB conversion.
28     */
29    struct Info {
30        SkISize fSize[3];
31        size_t  fSizeInMemory[3];
32        size_t  fRowBytes[3];
33        SkYUVColorSpace fColorSpace;
34    };
35    /**
36     * On success, return a ref to the SkCachedData that holds the pixels.
37     *
38     * On failure, return NULL.
39     */
40    static SkCachedData* FindAndRef(uint32_t genID, Info* info,
41                                    SkResourceCache* localCache = NULL);
42
43    /**
44     * Add a pixelRef ID and its YUV planes data to the cache.
45     */
46    static void Add(uint32_t genID, SkCachedData* data, Info* info,
47                    SkResourceCache* localCache = NULL);
48};
49
50#endif
51