aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/utils/SkPictureUtils.h
blob: c35aca81e2acc7b53d59df9ce132ac653d2637cc (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
/*
 * 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 SkPictureUtils_DEFINED
#define SkPictureUtils_DEFINED

#include "SkPicture.h"
#include "SkTDArray.h"

class SkData;
struct SkRect;

class SK_API SkPictureUtils {
public:
    /**
     *  Given a rectangular visible "window" into the picture, return an array
     *  of SkPixelRefs that might intersect that area. To keep the call fast,
     *  the returned list is not guaranteed to be exact, so it may miss some,
     *  and it may return false positives.
     *
     *  The pixelrefs returned in the SkData are already owned by the picture,
     *  so the returned pointers are only valid while the picture is in scope
     *  and remains unchanged.
     */
    static SkData* GatherPixelRefs(SkPicture* pict, const SkRect& area);

    /**
     * SkPixelRefContainer provides a base class for more elaborate pixel ref
     * query structures (e.g., rtrees, quad-trees, etc.)
     */
    class SkPixelRefContainer : public SkRefCnt {
    public:
        virtual void add(SkPixelRef* pr, const SkRect& rect) = 0;

        // The returned array may contain duplicates
        virtual void query(const SkRect& queryRect, SkTDArray<SkPixelRef*> *result) = 0;

    private:
        typedef SkRefCnt INHERITED;
    };

    // Simple query structure that just stores a linked list of pixel refs
    // and rects.
    class SkPixelRefsAndRectsList : public SkPixelRefContainer {
    public:
        virtual void add(SkPixelRef* pr, const SkRect& rect) SK_OVERRIDE {
            PixelRefAndRect *dst = fArray.append();

            dst->fPixelRef = pr;
            dst->fRect = rect;
        }

        virtual void query(const SkRect& queryRect, SkTDArray<SkPixelRef*> *result) SK_OVERRIDE {
            for (int i = 0; i < fArray.count(); ++i) {
                if (SkRect::Intersects(fArray[i].fRect, queryRect)) {
                    *result->append() = fArray[i].fPixelRef;
                }
            }
        }

    private:
        struct PixelRefAndRect {
            SkPixelRef* fPixelRef;
            SkRect      fRect;
        };

        SkTDArray<PixelRefAndRect> fArray;

        typedef SkPixelRefContainer INHERITED;
    };

    /**
     *  Fill the provided pixel ref container with the picture's pixel ref
     *  and rect information.
     */
    static void GatherPixelRefsAndRects(SkPicture* pict, SkPixelRefContainer* prCont);
};

#endif