OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPictureUtils_DEFINED | 8 #ifndef SkPictureUtils_DEFINED |
9 #define SkPictureUtils_DEFINED | 9 #define SkPictureUtils_DEFINED |
10 | 10 |
11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
12 #include "SkTDArray.h" | |
13 | |
14 class SkData; | |
15 struct SkRect; | |
16 | 12 |
17 class SK_API SkPictureUtils { | 13 class SK_API SkPictureUtils { |
18 public: | 14 public: |
19 /** | 15 /** |
20 * Given a rectangular visible "window" into the picture, return an array | |
21 * of SkPixelRefs that might intersect that area. To keep the call fast, | |
22 * the returned list is not guaranteed to be exact, so it may miss some, | |
23 * and it may return false positives. | |
24 * | |
25 * The pixelrefs returned in the SkData are already owned by the picture, | |
26 * so the returned pointers are only valid while the picture is in scope | |
27 * and remains unchanged. | |
28 */ | |
29 static SkData* GatherPixelRefs(const SkPicture* pict, const SkRect& area); | |
30 | |
31 /** | |
32 * SkPixelRefContainer provides a base class for more elaborate pixel ref | |
33 * query structures (e.g., rtrees, quad-trees, etc.) | |
34 */ | |
35 class SkPixelRefContainer : public SkRefCnt { | |
36 public: | |
37 virtual void add(SkPixelRef* pr, const SkRect& rect) = 0; | |
38 | |
39 // The returned array may contain duplicates | |
40 virtual void query(const SkRect& queryRect, SkTDArray<SkPixelRef*> *resu
lt) = 0; | |
41 | |
42 private: | |
43 typedef SkRefCnt INHERITED; | |
44 }; | |
45 | |
46 // Simple query structure that just stores a linked list of pixel refs | |
47 // and rects. | |
48 class SkPixelRefsAndRectsList : public SkPixelRefContainer { | |
49 public: | |
50 void add(SkPixelRef* pr, const SkRect& rect) SK_OVERRIDE { | |
51 PixelRefAndRect *dst = fArray.append(); | |
52 | |
53 dst->fPixelRef = pr; | |
54 dst->fRect = rect; | |
55 } | |
56 | |
57 void query(const SkRect& queryRect, SkTDArray<SkPixelRef*> *result) SK_O
VERRIDE { | |
58 for (int i = 0; i < fArray.count(); ++i) { | |
59 if (SkRect::Intersects(fArray[i].fRect, queryRect)) { | |
60 *result->append() = fArray[i].fPixelRef; | |
61 } | |
62 } | |
63 } | |
64 | |
65 private: | |
66 struct PixelRefAndRect { | |
67 SkPixelRef* fPixelRef; | |
68 SkRect fRect; | |
69 }; | |
70 | |
71 SkTDArray<PixelRefAndRect> fArray; | |
72 | |
73 typedef SkPixelRefContainer INHERITED; | |
74 }; | |
75 | |
76 /** | |
77 * Fill the provided pixel ref container with the picture's pixel ref | |
78 * and rect information. | |
79 */ | |
80 static void GatherPixelRefsAndRects(SkPicture* pict, SkPixelRefContainer* pr
Cont); | |
81 | |
82 /** | |
83 * How many bytes are allocated to hold the SkPicture. | 16 * How many bytes are allocated to hold the SkPicture. |
84 * Includes operations, parameters, bounding data, deletion listeners; | 17 * Includes operations, parameters, bounding data, deletion listeners; |
85 * includes nested SkPictures, but does not include large objects that | 18 * includes nested SkPictures, but does not include large objects that |
86 * SkRecord holds a reference to (e.g. paths, or pixels backing bitmaps). | 19 * SkRecord holds a reference to (e.g. paths, or pixels backing bitmaps). |
87 */ | 20 */ |
88 static size_t ApproximateBytesUsed(const SkPicture* pict); | 21 static size_t ApproximateBytesUsed(const SkPicture* pict); |
89 }; | 22 }; |
90 | 23 |
91 #endif | 24 #endif |
OLD | NEW |