gfx/skia/trunk/include/utils/SkPictureUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/utils/SkPictureUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkPictureUtils_DEFINED
    1.12 +#define SkPictureUtils_DEFINED
    1.13 +
    1.14 +#include "SkPicture.h"
    1.15 +#include "SkTDArray.h"
    1.16 +
    1.17 +class SkData;
    1.18 +struct SkRect;
    1.19 +
    1.20 +class SK_API SkPictureUtils {
    1.21 +public:
    1.22 +    /**
    1.23 +     *  Given a rectangular visible "window" into the picture, return an array
    1.24 +     *  of SkPixelRefs that might intersect that area. To keep the call fast,
    1.25 +     *  the returned list is not guaranteed to be exact, so it may miss some,
    1.26 +     *  and it may return false positives.
    1.27 +     *
    1.28 +     *  The pixelrefs returned in the SkData are already owned by the picture,
    1.29 +     *  so the returned pointers are only valid while the picture is in scope
    1.30 +     *  and remains unchanged.
    1.31 +     */
    1.32 +    static SkData* GatherPixelRefs(SkPicture* pict, const SkRect& area);
    1.33 +
    1.34 +    /**
    1.35 +     * SkPixelRefContainer provides a base class for more elaborate pixel ref
    1.36 +     * query structures (e.g., rtrees, quad-trees, etc.)
    1.37 +     */
    1.38 +    class SkPixelRefContainer : public SkRefCnt {
    1.39 +    public:
    1.40 +        virtual void add(SkPixelRef* pr, const SkRect& rect) = 0;
    1.41 +
    1.42 +        // The returned array may contain duplicates
    1.43 +        virtual void query(const SkRect& queryRect, SkTDArray<SkPixelRef*> *result) = 0;
    1.44 +
    1.45 +    private:
    1.46 +        typedef SkRefCnt INHERITED;
    1.47 +    };
    1.48 +
    1.49 +    // Simple query structure that just stores a linked list of pixel refs
    1.50 +    // and rects.
    1.51 +    class SkPixelRefsAndRectsList : public SkPixelRefContainer {
    1.52 +    public:
    1.53 +        virtual void add(SkPixelRef* pr, const SkRect& rect) SK_OVERRIDE {
    1.54 +            PixelRefAndRect *dst = fArray.append();
    1.55 +
    1.56 +            dst->fPixelRef = pr;
    1.57 +            dst->fRect = rect;
    1.58 +        }
    1.59 +
    1.60 +        virtual void query(const SkRect& queryRect, SkTDArray<SkPixelRef*> *result) SK_OVERRIDE {
    1.61 +            for (int i = 0; i < fArray.count(); ++i) {
    1.62 +                if (SkRect::Intersects(fArray[i].fRect, queryRect)) {
    1.63 +                    *result->append() = fArray[i].fPixelRef;
    1.64 +                }
    1.65 +            }
    1.66 +        }
    1.67 +
    1.68 +    private:
    1.69 +        struct PixelRefAndRect {
    1.70 +            SkPixelRef* fPixelRef;
    1.71 +            SkRect      fRect;
    1.72 +        };
    1.73 +
    1.74 +        SkTDArray<PixelRefAndRect> fArray;
    1.75 +
    1.76 +        typedef SkPixelRefContainer INHERITED;
    1.77 +    };
    1.78 +
    1.79 +    /**
    1.80 +     *  Fill the provided pixel ref container with the picture's pixel ref
    1.81 +     *  and rect information.
    1.82 +     */
    1.83 +    static void GatherPixelRefsAndRects(SkPicture* pict, SkPixelRefContainer* prCont);
    1.84 +};
    1.85 +
    1.86 +#endif

mercurial