diff options
author | 2014-03-07 15:53:01 +0000 | |
---|---|---|
committer | 2014-03-07 15:53:01 +0000 | |
commit | 8016f79cfc6b4e9b34049ecbccdb65ee222d537a (patch) | |
tree | 444f455f15ca0186129d949b4dc260e1d2315669 /src/core/SkOffsetTable.h | |
parent | 8eb20cc112c2eefc08f5102bd96f9ae1f75b9e54 (diff) |
This is just the first version and shows how I intend to orchestrate this. Future enhancements will:
track the portion of the bitmap required
track any resizing that might be required
actually preload something
R=bsalomon@google.com, mtklein@google.com
Author: robertphillips@google.com
Review URL: https://codereview.chromium.org/187833003
git-svn-id: http://skia.googlecode.com/svn/trunk@13704 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkOffsetTable.h')
-rw-r--r-- | src/core/SkOffsetTable.h | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/core/SkOffsetTable.h b/src/core/SkOffsetTable.h new file mode 100644 index 0000000000..60c62642b2 --- /dev/null +++ b/src/core/SkOffsetTable.h @@ -0,0 +1,115 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkOffsetTable_DEFINED +#define SkOffsetTable_DEFINED + +#include "SkRefCnt.h" +#include "SkTDArray.h" + +// A 2D table of skp offsets. Each row is indexed by an int. This is used +// to store the command offsets that reference a particular bitmap using +// the bitmap's index in the bitmap heap as the 'id' here. It has to be +// ref-countable so SkPicturePlayback can take ownership of it. +// Note that this class assumes that the ids are densely packed. + +// TODO: This needs to be sped up. We could replace the offset table with +// a hash table. +class SkOffsetTable : public SkRefCnt { +public: + SkOffsetTable() {} + ~SkOffsetTable() { + fOffsetArrays.deleteAll(); + } + + // Record that this 'id' is used by the command starting at this 'offset'. + // Offsets for a given 'id' should always be added in increasing order. + void add(int id, size_t offset) { + if (id >= fOffsetArrays.count()) { + int oldCount = fOffsetArrays.count(); + fOffsetArrays.setCount(id+1); + for (int i = oldCount; i <= id; ++i) { + fOffsetArrays[i] = NULL; + } + } + + if (NULL == fOffsetArrays[id]) { + fOffsetArrays[id] = SkNEW(OffsetArray); + } + fOffsetArrays[id]->add(offset); + } + + int numIDs() const { + return fOffsetArrays.count(); + } + + // Do the offsets of any commands referencing this ID fall in the + // range [min, max] (both inclusive) + bool overlap(int id, size_t min, size_t max) { + SkASSERT(id < fOffsetArrays.count()); + + if (NULL == fOffsetArrays[id]) { + return false; + } + + // If this id has an offset array it should have at least one use + SkASSERT(fOffsetArrays[id]->count() > 0); + if (max < fOffsetArrays[id]->min() || min > fOffsetArrays[id]->max()) { + return false; + } + + return true; + } + + bool includes(int id, size_t offset) { + SkASSERT(id < fOffsetArrays.count()); + + OffsetArray* array = fOffsetArrays[id]; + + for (int i = 0; i < array->fOffsets.count(); ++i) { + if (array->fOffsets[i] == offset) { + return true; + } else if (array->fOffsets[i] > offset) { + return false; + } + } + + // Calls to 'includes' should be gaurded by an overlap() call, so we + // should always find something. + SkASSERT(0); + return false; + } + +protected: + class OffsetArray { + public: + void add(size_t offset) { + SkASSERT(fOffsets.count() == 0 || offset > this->max()); + *fOffsets.append() = offset; + } + size_t min() const { + SkASSERT(fOffsets.count() > 0); + return fOffsets[0]; + } + size_t max() const { + SkASSERT(fOffsets.count() > 0); + return fOffsets[fOffsets.count()-1]; + } + int count() const { + return fOffsets.count(); + } + + SkTDArray<size_t> fOffsets; + }; + + SkTDArray<OffsetArray*> fOffsetArrays; + +private: + typedef SkRefCnt INHERITED; +}; + +#endif |