SkBBHFactory.cpp revision 534cc4c569d88c1cfa5f10d3ecf475a90278f597
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#include "SkBBHFactory.h"
9#include "SkQuadTree.h"
10#include "SkRTree.h"
11#include "SkTileGrid.h"
12
13
14SkBBoxHierarchy* SkQuadTreeFactory::operator()(int width, int height) const {
15    return SkNEW_ARGS(SkQuadTree, (SkIRect::MakeWH(width, height)));
16}
17
18SkBBoxHierarchy* SkRTreeFactory::operator()(int width, int height) const {
19    // These values were empirically determined to produce reasonable
20    // performance in most cases.
21    static const int kRTreeMinChildren = 6;
22    static const int kRTreeMaxChildren = 11;
23
24    SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width),
25                                       SkIntToScalar(height));
26    bool sortDraws = false;  // Do not sort draw calls when bulk loading.
27
28    return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren,
29                           aspectRatio, sortDraws);
30}
31
32SkBBoxHierarchy* SkTileGridFactory::operator()(int width, int height) const {
33    SkASSERT(fInfo.fMargin.width() >= 0);
34    SkASSERT(fInfo.fMargin.height() >= 0);
35    // Note: SkIRects are non-inclusive of the right() column and bottom() row.
36    // For example, an SkIRect at 0,0 with a size of (1,1) will only have
37    // content at pixel (0,0) and will report left=0 and right=1, hence the
38    // "-1"s below.
39    int xTileCount = (width + fInfo.fTileInterval.width() - 1) / fInfo.fTileInterval.width();
40    int yTileCount = (height + fInfo.fTileInterval.height() - 1) / fInfo.fTileInterval.height();
41    return SkNEW_ARGS(SkTileGrid, (xTileCount, yTileCount, fInfo));
42}
43