| 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkBBHFactory_DEFINED |
| 9 | #define SkBBHFactory_DEFINED |
| 10 | |
| 11 | #include "include/core/SkRect.h" |
| 12 | #include "include/core/SkRefCnt.h" |
| 13 | #include "include/core/SkTypes.h" |
| 14 | #include <vector> |
| 15 | |
| 16 | class SkBBoxHierarchy : public SkRefCnt { |
| 17 | public: |
| 18 | SkBBoxHierarchy() {} |
| 19 | |
| 20 | struct Metadata { |
| 21 | bool isDraw; // The corresponding SkRect bounds a draw command, not a pure state change. |
| 22 | }; |
| 23 | |
| 24 | /** |
| 25 | * Insert N bounding boxes into the hierarchy. |
| 26 | */ |
| 27 | virtual void insert(const SkRect[], int N) = 0; |
| 28 | virtual void insert(const SkRect[], const Metadata[], int N); |
| 29 | |
| 30 | /** |
| 31 | * Populate results with the indices of bounding boxes intersecting that query. |
| 32 | */ |
| 33 | virtual void search(const SkRect& query, std::vector<int>* results) const = 0; |
| 34 | |
| 35 | /** |
| 36 | * Return approximate size in memory of *this. |
| 37 | */ |
| 38 | virtual size_t bytesUsed() const = 0; |
| 39 | }; |
| 40 | |
| 41 | class SK_API SkBBHFactory { |
| 42 | public: |
| 43 | /** |
| 44 | * Allocate a new SkBBoxHierarchy. Return NULL on failure. |
| 45 | */ |
| 46 | virtual sk_sp<SkBBoxHierarchy> operator()() const = 0; |
| 47 | virtual ~SkBBHFactory() {} |
| 48 | }; |
| 49 | |
| 50 | class SK_API SkRTreeFactory : public SkBBHFactory { |
| 51 | public: |
| 52 | sk_sp<SkBBoxHierarchy> operator()() const override; |
| 53 | }; |
| 54 | |
| 55 | #endif |
| 56 | |