michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkPictureUtils_DEFINED michael@0: #define SkPictureUtils_DEFINED michael@0: michael@0: #include "SkPicture.h" michael@0: #include "SkTDArray.h" michael@0: michael@0: class SkData; michael@0: struct SkRect; michael@0: michael@0: class SK_API SkPictureUtils { michael@0: public: michael@0: /** michael@0: * Given a rectangular visible "window" into the picture, return an array michael@0: * of SkPixelRefs that might intersect that area. To keep the call fast, michael@0: * the returned list is not guaranteed to be exact, so it may miss some, michael@0: * and it may return false positives. michael@0: * michael@0: * The pixelrefs returned in the SkData are already owned by the picture, michael@0: * so the returned pointers are only valid while the picture is in scope michael@0: * and remains unchanged. michael@0: */ michael@0: static SkData* GatherPixelRefs(SkPicture* pict, const SkRect& area); michael@0: michael@0: /** michael@0: * SkPixelRefContainer provides a base class for more elaborate pixel ref michael@0: * query structures (e.g., rtrees, quad-trees, etc.) michael@0: */ michael@0: class SkPixelRefContainer : public SkRefCnt { michael@0: public: michael@0: virtual void add(SkPixelRef* pr, const SkRect& rect) = 0; michael@0: michael@0: // The returned array may contain duplicates michael@0: virtual void query(const SkRect& queryRect, SkTDArray *result) = 0; michael@0: michael@0: private: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: // Simple query structure that just stores a linked list of pixel refs michael@0: // and rects. michael@0: class SkPixelRefsAndRectsList : public SkPixelRefContainer { michael@0: public: michael@0: virtual void add(SkPixelRef* pr, const SkRect& rect) SK_OVERRIDE { michael@0: PixelRefAndRect *dst = fArray.append(); michael@0: michael@0: dst->fPixelRef = pr; michael@0: dst->fRect = rect; michael@0: } michael@0: michael@0: virtual void query(const SkRect& queryRect, SkTDArray *result) SK_OVERRIDE { michael@0: for (int i = 0; i < fArray.count(); ++i) { michael@0: if (SkRect::Intersects(fArray[i].fRect, queryRect)) { michael@0: *result->append() = fArray[i].fPixelRef; michael@0: } michael@0: } michael@0: } michael@0: michael@0: private: michael@0: struct PixelRefAndRect { michael@0: SkPixelRef* fPixelRef; michael@0: SkRect fRect; michael@0: }; michael@0: michael@0: SkTDArray fArray; michael@0: michael@0: typedef SkPixelRefContainer INHERITED; michael@0: }; michael@0: michael@0: /** michael@0: * Fill the provided pixel ref container with the picture's pixel ref michael@0: * and rect information. michael@0: */ michael@0: static void GatherPixelRefsAndRects(SkPicture* pict, SkPixelRefContainer* prCont); michael@0: }; michael@0: michael@0: #endif