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
16class SkBBoxHierarchy : public SkRefCnt {
17public:
18 SkBBoxHierarchy() {}
19 virtual ~SkBBoxHierarchy() {}
20
21 struct Metadata {
22 bool isDraw; // The corresponding SkRect bounds a draw command, not a pure state change.
23 };
24
25 /**
26 * Insert N bounding boxes into the hierarchy.
27 */
28 virtual void insert(const SkRect[], int N) = 0;
29 virtual void insert(const SkRect[], const Metadata[], int N);
30
31 /**
32 * Populate results with the indices of bounding boxes intersecting that query.
33 */
34 virtual void search(const SkRect& query, std::vector<int>* results) const = 0;
35
36 /**
37 * Return approximate size in memory of *this.
38 */
39 virtual size_t bytesUsed() const = 0;
40};
41
42class SK_API SkBBHFactory {
43public:
44 /**
45 * Allocate a new SkBBoxHierarchy. Return NULL on failure.
46 */
47 virtual sk_sp<SkBBoxHierarchy> operator()() const = 0;
48 virtual ~SkBBHFactory() {}
49};
50
51class SK_API SkRTreeFactory : public SkBBHFactory {
52public:
53 sk_sp<SkBBoxHierarchy> operator()() const override;
54};
55
56#endif
57