2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "GrPathRange.h"
12 kPathsPerGroup = 16 // Paths get tracked in groups of 16 for lazy loading.
15 GrPathRange::GrPathRange(GrGpu* gpu,
16 PathGenerator* pathGenerator,
17 const SkStrokeRec& stroke)
18 : INHERITED(gpu, kIsWrapped),
19 fPathGenerator(SkRef(pathGenerator)),
20 fNumPaths(fPathGenerator->getNumPaths()),
22 const int numGroups = (fNumPaths + kPathsPerGroup - 1) / kPathsPerGroup;
23 fGeneratedPaths.reset((numGroups + 7) / 8); // 1 bit per path group.
24 memset(&fGeneratedPaths.front(), 0, fGeneratedPaths.count());
27 GrPathRange::GrPathRange(GrGpu* gpu,
29 const SkStrokeRec& stroke)
30 : INHERITED(gpu, kIsWrapped),
35 void GrPathRange::willDrawPaths(const uint32_t indices[], int count) const {
36 if (NULL == fPathGenerator.get()) {
40 bool didLoadPaths = false;
42 for (int i = 0; i < count; ++i) {
43 SkASSERT(indices[i] < static_cast<uint32_t>(fNumPaths));
45 const int groupIndex = indices[i] / kPathsPerGroup;
46 const int groupByte = groupIndex / 8;
47 const uint8_t groupBit = 1 << (groupIndex % 8);
49 const bool hasPath = SkToBool(fGeneratedPaths[groupByte] & groupBit);
51 // We track which paths are loaded in groups of kPathsPerGroup. To
52 // mark a path as loaded we need to load the entire group.
53 const int groupFirstPath = groupIndex * kPathsPerGroup;
54 const int groupLastPath = SkTMin(groupFirstPath + kPathsPerGroup, fNumPaths) - 1;
57 for (int pathIdx = groupFirstPath; pathIdx <= groupLastPath; ++pathIdx) {
58 fPathGenerator->generatePath(pathIdx, &path);
59 this->onInitPath(pathIdx, path);
62 fGeneratedPaths[groupByte] |= groupBit;
68 this->didChangeGpuMemorySize();