aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/lazy/SkBitmapFactory.h
blob: bebd3a7ceea5c1f777a3617b5123233524d18dcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkBitmapFactory_DEFINED
#define SkBitmapFactory_DEFINED

#include "SkImage.h"
#include "SkTypes.h"

class SkBitmap;
class SkData;
class SkImageCache;

/**
 *  Factory for creating a bitmap from encoded data.
 */
class SkBitmapFactory {

public:
    /**
     *  Struct containing information about a pixel destination.
     */
    struct Target {
        /**
         *  Pre-allocated memory.
         */
        void*  fAddr;

        /**
         *  Rowbytes of the allocated memory.
         */
        size_t fRowBytes;
    };

    /**
     *  Signature for a function to decode an image from encoded data.
     */
    typedef bool (*DecodeProc)(const void* data, size_t length, SkImage::Info*, const Target*);

    /**
     *  Create a bitmap factory which uses DecodeProc for decoding.
     *  @param DecodeProc Must not be NULL.
     */
    SkBitmapFactory(DecodeProc);

    ~SkBitmapFactory();

    /**
     *  Set an image cache to use on pixelrefs provided by installPixelRef. Mutually exclusive
     *  with fCacheSelector.
     */
    void setImageCache(SkImageCache* cache);

    /**
     *  Sets up an SkBitmap from encoded data. On success, the SkBitmap will have its Config,
     *  width, height, rowBytes and pixelref set. If fImageCache is non-NULL, or if fCacheSelector
     *  is set and returns non-NULL, the pixelref will lazily decode, and that SkImageCache will
     *  handle the pixel memory. Otherwise installPixelRef will do an immediate decode.
     *  @param SkData Encoded data.
     *  @param SkBitmap to install the pixel ref on.
     *  @return bool Whether or not a pixel ref was successfully installed.
     */
    bool installPixelRef(SkData*, SkBitmap*);

    /**
     *  A function for selecting an SkImageCache to use based on an SkImage::Info.
     */
    typedef SkImageCache* (*CacheSelector)(const SkImage::Info&);

    /**
     *  Set the function to be used to select which SkImageCache to use. Mutually exclusive with
     *  fImageCache.
     */
    void setCacheSelector(CacheSelector);

private:
    DecodeProc    fDecodeProc;
    SkImageCache* fImageCache;
    CacheSelector fCacheSelector;
};

#endif // SkBitmapFactory_DEFINED