aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTileGridPicture.h
blob: 6dbe2fc63b3acdf3787f23657f6dce9453670fbd (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
87
88
89
/*
 * 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 SkTileGridPicture_DEFINED
#define SkTileGridPicture_DEFINED

#include "SkPicture.h"
#include "SkPoint.h"
#include "SkSize.h"

class SkTileGridFactory : public SkBBHFactory {
public:
    struct TileGridInfo {
        /** Tile placement interval */
        SkISize  fTileInterval;

        /** Pixel coverage overlap between adjacent tiles */
        SkISize  fMargin;

        /** Offset added to device-space bounding box positions to convert
          * them to tile-grid space. This can be used to adjust the "phase"
          * of the tile grid to match probable query rectangles that will be
          * used to search into the tile grid. As long as the offset is smaller
          * or equal to the margin, there is no need to extend the domain of
          * the tile grid to prevent data loss.
          */
        SkIPoint fOffset;
    };

    SkTileGridFactory(const TileGridInfo& info) : fInfo(info) { }

    virtual SkBBoxHierarchy* operator()(int width, int height) const SK_OVERRIDE;

private:
    TileGridInfo fInfo;

    typedef SkBBHFactory INHERITED;
};

#ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES

/**
 * Subclass of SkPicture that creates an SkTileGrid. The tile grid has lower recording
 * and playback costs then rTree, but is less effective at eliminating extraneous
 * primitives for arbitrary query rectangles. It is most effective for
 * tiled playback when the tile structure is known at record time.
 */
class SK_API SkTileGridPicture : public SkPicture {
public:
    typedef SkTileGridFactory::TileGridInfo TileGridInfo;

    /**
     * Constructor
     * @param width recording canvas width in device pixels
     * @param height recording canvas height in device pixels
     * @param info description of the tiling layout
     */
    SkTileGridPicture(int width, int height, const SkTileGridFactory::TileGridInfo& info);

    virtual SkBBoxHierarchy* createBBoxHierarchy() const SK_OVERRIDE;

private:
    int fXTileCount, fYTileCount;
    SkTileGridFactory::TileGridInfo fInfo;

    typedef SkPicture INHERITED;
};

class SkTileGridPictureFactory : public SkPictureFactory {
public:
    SkTileGridPictureFactory(const SkTileGridFactory::TileGridInfo& info) : fInfo(info) { }

    virtual SkPicture* create(int width, int height) SK_OVERRIDE {
        return SkNEW_ARGS(SkTileGridPicture, (width, height, fInfo));
    }

protected:
    SkTileGridFactory::TileGridInfo fInfo;

private:
    typedef SkPictureFactory INHERITED;
};
#endif

#endif