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