1770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com/* 2770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com * Copyright 2014 Google Inc. 3770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com * 4770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be 5770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com * found in the LICENSE file. 6770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com */ 7770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com 8770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com#include "SkBBHFactory.h" 9770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com#include "SkRTree.h" 10770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com#include "SkTileGrid.h" 11770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com 12770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com 13770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.comSkBBoxHierarchy* SkRTreeFactory::operator()(int width, int height) const { 14770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com // These values were empirically determined to produce reasonable 15770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com // performance in most cases. 16770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com static const int kRTreeMinChildren = 6; 17770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com static const int kRTreeMaxChildren = 11; 18770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com 19770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(width), 20770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com SkIntToScalar(height)); 21770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com bool sortDraws = false; // Do not sort draw calls when bulk loading. 22770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com 23770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren, 24770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com aspectRatio, sortDraws); 25770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com} 26770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com 27770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.comSkBBoxHierarchy* SkTileGridFactory::operator()(int width, int height) const { 28770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com SkASSERT(fInfo.fMargin.width() >= 0); 29770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com SkASSERT(fInfo.fMargin.height() >= 0); 30770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com // Note: SkIRects are non-inclusive of the right() column and bottom() row. 31770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com // For example, an SkIRect at 0,0 with a size of (1,1) will only have 32770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com // content at pixel (0,0) and will report left=0 and right=1, hence the 33770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com // "-1"s below. 34770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com int xTileCount = (width + fInfo.fTileInterval.width() - 1) / fInfo.fTileInterval.width(); 35770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com int yTileCount = (height + fInfo.fTileInterval.height() - 1) / fInfo.fTileInterval.height(); 36534cc4c569d88c1cfa5f10d3ecf475a90278f597mtklein return SkNEW_ARGS(SkTileGrid, (xTileCount, yTileCount, fInfo)); 37770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com} 38