void onDraw(const int loops, SkCanvas* canvas) override {
SkRandom rand;
for (int i = 0; i < loops; ++i) {
- SkTDArray<unsigned> hits;
+ SkTDArray<int> hits;
SkRect query;
query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
macroCanvas,
drawables ? *drawables : empty,
};
- for (unsigned i = 0; i < skr.count(); i++) {
+ for (int i = 0; i < skr.count(); i++) {
skr.visit<void>(i, drawsAsSingletonPictures);
}
SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
/**
* Populate results with the indices of bounding boxes interesecting that query.
*/
- virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const = 0;
+ virtual void search(const SkRect& query, SkTDArray<int>* results) const = 0;
virtual size_t bytesUsed() const = 0;
// Get the root bound.
virtual SkRect getRootBound() const = 0;
-
+
private:
typedef SkRefCnt INHERITED;
};
}
void SkBigPicture::partialPlayback(SkCanvas* canvas,
- unsigned start,
- unsigned stop,
+ int start,
+ int stop,
const SkMatrix& initialCTM) const {
SkASSERT(canvas);
SkRecordPartialDraw(*fRecord,
SkPathCounter path;
bool hasText = false, hasBitmap = false;
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
hasText = hasText || record.visit<bool>(i, text);
hasBitmap = hasBitmap || record.visit<bool>(i, bitmap);
record.visit<void>(i, path);
// Used by GrLayerHoister
void partialPlayback(SkCanvas*,
- unsigned start,
- unsigned stop,
+ int start,
+ int stop,
const SkMatrix& initialCTM) const;
// Used by GrRecordReplaceDraw
const SkBBoxHierarchy* bbh() const { return fBBH; }
// The variable length key for this saveLayer block. It stores the
// thread of drawPicture and saveLayer operation indices that lead to this
// saveLayer (including its own op index). The BlockInfo owns this memory.
- unsigned* fKey;
- int fKeySize; // # of ints
+ int* fKey;
+ int fKeySize; // # of ints
};
SkLayerInfo() {}
return this->bulkLoad(branches, level + 1);
}
-void SkRTree::search(const SkRect& query, SkTDArray<unsigned>* results) const {
+void SkRTree::search(const SkRect& query, SkTDArray<int>* results) const {
if (fCount > 0 && SkRect::Intersects(fRoot.fBounds, query)) {
this->search(fRoot.fSubtree, query, results);
}
}
-void SkRTree::search(Node* node, const SkRect& query, SkTDArray<unsigned>* results) const {
+void SkRTree::search(Node* node, const SkRect& query, SkTDArray<int>* results) const {
for (int i = 0; i < node->fNumChildren; ++i) {
if (SkRect::Intersects(node->fChildren[i].fBounds, query)) {
if (0 == node->fLevel) {
*/
class SkRTree : public SkBBoxHierarchy {
public:
-
+
/**
* If you have some prior information about the distribution of bounds you're expecting, you
virtual ~SkRTree() {}
void insert(const SkRect[], int N) override;
- void search(const SkRect& query, SkTDArray<unsigned>* results) const override;
+ void search(const SkRect& query, SkTDArray<int>* results) const override;
size_t bytesUsed() const override;
// Methods and constants below here are only public for tests.
struct Branch {
union {
Node* fSubtree;
- unsigned fOpIndex;
+ int fOpIndex;
};
SkRect fBounds;
};
Branch fChildren[kMaxChildren];
};
- void search(Node* root, const SkRect& query, SkTDArray<unsigned>* results) const;
+ void search(Node* root, const SkRect& query, SkTDArray<int>* results) const;
// Consumes the input array.
Branch bulkLoad(SkTDArray<Branch>* branches, int level = 0);
SkRecord::~SkRecord() {
Destroyer destroyer;
- for (unsigned i = 0; i < this->count(); i++) {
+ for (int i = 0; i < this->count(); i++) {
this->mutate<void>(i, destroyer);
}
}
~SkRecord();
// Returns the number of canvas commands in this SkRecord.
- unsigned count() const { return fCount; }
+ int count() const { return fCount; }
// Visit the i-th canvas command with a functor matching this interface:
// template <typename T>
// R operator()(const T& record) { ... }
// This operator() must be defined for at least all SkRecords::*.
template <typename R, typename F>
- R visit(unsigned i, F& f) const {
+ R visit(int i, F& f) const {
SkASSERT(i < this->count());
return fRecords[i].visit<R>(f);
}
// R operator()(T* record) { ... }
// This operator() must be defined for at least all SkRecords::*.
template <typename R, typename F>
- R mutate(unsigned i, F& f) {
+ R mutate(int i, F& f) {
SkASSERT(i < this->count());
return fRecords[i].mutate<R>(f);
}
// You are expected to placement new an object of type T onto this pointer.
// References to the original command are invalidated.
template <typename T>
- T* replace(unsigned i) {
+ T* replace(int i) {
SkASSERT(i < this->count());
Destroyer destroyer;
// You are expected to placement new an object of type T onto this pointer.
// You must show proof that you've already adopted the existing command.
template <typename T, typename Existing>
- T* replace(unsigned i, const SkRecords::Adopted<Existing>& proofOfAdoption) {
+ T* replace(int i, const SkRecords::Adopted<Existing>& proofOfAdoption) {
SkASSERT(i < this->count());
SkASSERT(Existing::kType == fRecords[i].type());
// fRecords needs to be a data structure that can append fixed length data, and need to
// support efficient random access and forward iteration. (It doesn't need to be contiguous.)
- unsigned fCount, fReserved;
+ int fCount, fReserved;
SkAutoSTMalloc<kInlineRecords, Record> fRecords;
// fAlloc needs to be a data structure which can append variable length data in contiguous
query.setEmpty();
}
- SkTDArray<unsigned> ops;
+ SkTDArray<int> ops;
bbh->search(query, &ops);
SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount);
} else {
// Draw all ops.
SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount);
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
if (callback && callback->abort()) {
return;
}
void SkRecordPartialDraw(const SkRecord& record, SkCanvas* canvas,
SkPicture const* const drawablePicts[], int drawableCount,
- unsigned start, unsigned stop,
+ int start, int stop,
const SkMatrix& initialCTM) {
SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
stop = SkTMin(stop, record.count());
SkRecords::Draw draw(canvas, drawablePicts, NULL, drawableCount, &initialCTM);
- for (unsigned i = start; i < stop; i++) {
+ for (int i = start; i < stop; i++) {
record.visit<void>(i, draw);
}
}
fCurrentClipBounds = fCullRect;
}
- void setCurrentOp(unsigned currentOp) { fCurrentOp = currentOp; }
+ void setCurrentOp(int currentOp) { fCurrentOp = currentOp; }
void cleanUp(SkBBoxHierarchy* bbh) {
// If we have any lingering unpaired Saves, simulate restores to make
// In this file, SkRect are in local coordinates, Bounds are translated back to identity space.
typedef SkRect Bounds;
- unsigned currentOp() const { return fCurrentOp; }
+ int currentOp() const { return fCurrentOp; }
const SkMatrix& ctm() const { return *fCTM; }
- const Bounds& getBounds(unsigned index) const { return fBounds[index]; }
+ const Bounds& getBounds(int index) const { return fBounds[index]; }
// Adjust rect for all paints that may affect its geometry, then map it to identity space.
Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const {
return true;
}
- const unsigned fNumRecords;
+ const int fNumRecords;
// We do not guarantee anything for operations outside of the cull rect
const SkRect fCullRect;
// We walk fCurrentOp through the SkRecord, as we go using updateCTM()
// and updateClipBounds() to maintain the exact CTM (fCTM) and conservative
// identity-space bounds of the current clip (fCurrentClipBounds).
- unsigned fCurrentOp;
+ int fCurrentOp;
const SkMatrix* fCTM;
Bounds fCurrentClipBounds;
// Used to track the bounds of Save/Restore blocks and the control ops inside them.
SkTDArray<SaveBounds> fSaveStack;
- SkTDArray<unsigned> fControlIndices;
+ SkTDArray<int> fControlIndices;
};
// SkRecord visitor to gather saveLayer/restore information.
, fFillBounds(cullRect, record)
{}
- void setCurrentOp(unsigned currentOp) { fFillBounds.setCurrentOp(currentOp); }
+ void setCurrentOp(int currentOp) { fFillBounds.setCurrentOp(currentOp); }
void cleanUp(SkBBoxHierarchy* bbh) {
// fFillBounds must perform its cleanUp first so that all the bounding
// Store 'saveLayer ops from enclosing picture' + drawPict op + 'ops from sub-picture'
dst.fKeySize = fSaveLayerOpStack.count() + src.fKeySize + 1;
- dst.fKey = SkNEW_ARRAY(unsigned, dst.fKeySize);
- memcpy(dst.fKey, fSaveLayerOpStack.begin(), fSaveLayerOpStack.count() * sizeof(unsigned));
+ dst.fKey = SkNEW_ARRAY(int, dst.fKeySize);
+ memcpy(dst.fKey, fSaveLayerOpStack.begin(), fSaveLayerOpStack.count() * sizeof(int));
dst.fKey[fSaveLayerOpStack.count()] = fFillBounds.currentOp();
- memcpy(&dst.fKey[fSaveLayerOpStack.count()+1], src.fKey, src.fKeySize * sizeof(unsigned));
+ memcpy(&dst.fKey[fSaveLayerOpStack.count()+1], src.fKey, src.fKeySize * sizeof(int));
}
}
block.fIsNested = fSaveLayersInStack > 0;
block.fKeySize = fSaveLayerOpStack.count();
- block.fKey = SkNEW_ARRAY(unsigned, block.fKeySize);
- memcpy(block.fKey, fSaveLayerOpStack.begin(), block.fKeySize * sizeof(unsigned));
+ block.fKey = SkNEW_ARRAY(int, block.fKeySize);
+ memcpy(block.fKey, fSaveLayerOpStack.begin(), block.fKeySize * sizeof(int));
fSaveLayerOpStack.pop();
}
int fSaveLayersInStack;
SkTDArray<SaveLayerInfo> fSaveLayerStack;
// The op code indices of all the currently active saveLayers
- SkTDArray<unsigned> fSaveLayerOpStack;
+ SkTDArray<int> fSaveLayerOpStack;
SkLayerInfo* fAccelData;
const SkBigPicture::SnapshotArray* fPictList;
void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkBBoxHierarchy* bbh) {
SkRecords::FillBounds visitor(cullRect, record);
- for (unsigned curOp = 0; curOp < record.count(); curOp++) {
+ for (int curOp = 0; curOp < record.count(); curOp++) {
visitor.setCurrentOp(curOp);
record.visit<void>(curOp, visitor);
}
SkLayerInfo* data) {
SkRecords::CollectLayers visitor(cullRect, record, pictList, data);
- for (unsigned curOp = 0; curOp < record.count(); curOp++) {
+ for (int curOp = 0; curOp < record.count(); curOp++) {
visitor.setCurrentOp(curOp);
record.visit<void>(curOp, visitor);
}
// the initialCTM parameter must set to just the replay matrix.
void SkRecordPartialDraw(const SkRecord&, SkCanvas*,
SkPicture const* const drawablePicts[], int drawableCount,
- unsigned start, unsigned stop, const SkMatrix& initialCTM);
+ int start, int stop, const SkMatrix& initialCTM);
namespace SkRecords {
// Most of the optimizations in this file are pattern-based. These are all defined as structs with:
// - a Pattern typedef
-// - a bool onMatch(SkRceord*, Pattern*, unsigned begin, unsigned end) method,
+// - a bool onMatch(SkRceord*, Pattern*, int begin, int end) method,
// which returns true if it made changes and false if not.
// Run a pattern-based optimization once across the SkRecord, returning true if it made any changes.
static bool apply(Pass* pass, SkRecord* record) {
typename Pass::Pattern pattern;
bool changed = false;
- unsigned begin, end = 0;
+ int begin, end = 0;
while (pattern.search(record, &begin, &end)) {
changed |= pass->onMatch(record, &pattern, begin, end);
Is<Restore> >
Pattern;
- bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned end) {
+ bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
record->replace<NoOp>(begin); // Save
record->replace<NoOp>(end-1); // Restore
return true;
Is<Restore> >
Pattern;
- bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned end) {
+ bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
// The entire span between Save and Restore (inclusively) does nothing.
- for (unsigned i = begin; i < end; i++) {
+ for (int i = begin; i < end; i++) {
record->replace<NoOp>(i);
}
return true;
struct SaveLayerDrawRestoreNooper {
typedef Pattern3<Is<SaveLayer>, IsDraw, Is<Restore> > Pattern;
- bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned end) {
+ bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
// A SaveLayer's bounds field is just a hint, so we should be free to ignore it.
SkPaint* layerPaint = pattern->first<SaveLayer>()->paint;
if (NULL == layerPaint) {
return KillSaveLayerAndRestore(record, begin);
}
- static bool KillSaveLayerAndRestore(SkRecord* record, unsigned saveLayerIndex) {
+ static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) {
record->replace<NoOp>(saveLayerIndex); // SaveLayer
record->replace<NoOp>(saveLayerIndex+2); // Restore
return true;
typedef Pattern7<Is<SaveLayer>, Is<Save>, Is<ClipRect>, Is<SaveLayer>,
Is<Restore>, Is<Restore>, Is<Restore> > Pattern;
- bool onMatch(SkRecord* record, Pattern* pattern, unsigned begin, unsigned end) {
+ bool onMatch(SkRecord* record, Pattern* pattern, int begin, int end) {
SkPaint* opacityPaint = pattern->first<SaveLayer>()->paint;
if (NULL == opacityPaint) {
// There wasn't really any point to this SaveLayer at all.
return KillSaveLayerAndRestore(record, begin);
}
- static bool KillSaveLayerAndRestore(SkRecord* record, unsigned saveLayerIndex) {
+ static bool KillSaveLayerAndRestore(SkRecord* record, int saveLayerIndex) {
record->replace<NoOp>(saveLayerIndex); // SaveLayer
record->replace<NoOp>(saveLayerIndex + 6); // Restore
return true;
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkRecordPattern_DEFINED
#define SkRecordPattern_DEFINED
public:
// If this pattern matches the SkRecord starting at i,
// return the index just past the end of the pattern, otherwise return 0.
- SK_ALWAYS_INLINE unsigned match(SkRecord* record, unsigned i) {
+ SK_ALWAYS_INLINE int match(SkRecord* record, int i) {
i = this->matchHead(&fHead, record, i);
return i == 0 ? 0 : fTail.match(record, i);
}
// Starting from *end, walk through the SkRecord to find the first span matching this pattern.
// If there is no such span, return false. If there is, return true and set [*begin, *end).
- SK_ALWAYS_INLINE bool search(SkRecord* record, unsigned* begin, unsigned* end) {
+ SK_ALWAYS_INLINE bool search(SkRecord* record, int* begin, int* end) {
for (*begin = *end; *begin < record->count(); ++(*begin)) {
*end = this->match(record, *begin);
if (*end != 0) {
private:
// If head isn't a Star, try to match at i once.
template <typename T>
- unsigned matchHead(T*, SkRecord* record, unsigned i) {
+ int matchHead(T*, SkRecord* record, int i) {
if (i < record->count()) {
if (record->mutate<bool>(i, fHead)) {
return i+1;
// If head is a Star, walk i until it doesn't match.
template <typename T>
- unsigned matchHead(Star<T>*, SkRecord* record, unsigned i) {
+ int matchHead(Star<T>*, SkRecord* record, int i) {
while (i < record->count()) {
if (!record->mutate<bool>(i, fHead)) {
return i;
// Nil is the end of every pattern Cons chain.
struct Nil {
// Bottoms out recursion down the fTail chain. Just return whatever i the front decided on.
- unsigned match(SkRecord*, unsigned i) { return i; }
+ int match(SkRecord*, int i) { return i; }
};
// These Pattern# types are syntax sugar over Cons and Nil, just to help eliminate some of the
void SkRecorder::onDrawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint) {
- const unsigned points = paint.countText(text, byteLength);
+ const int points = paint.countText(text, byteLength);
APPEND(DrawPosText,
paint,
this->copy((const char*)text, byteLength),
void SkRecorder::onDrawPosTextH(const void* text, size_t byteLength,
const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
- const unsigned points = paint.countText(text, byteLength);
+ const int points = paint.countText(text, byteLength);
APPEND(DrawPosTextH,
paint,
this->copy((const char*)text, byteLength),
const SkIRect& srcIR,
const SkIRect& dstIR,
const SkMatrix& initialMat,
- const unsigned* key,
+ const int* key,
int keySize,
const SkPaint* paint) {
SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
}
GrCachedLayer* GrLayerCache::findLayer(uint32_t pictureID, const SkMatrix& initialMat,
- const unsigned* key, int keySize) {
+ const int* key, int keySize) {
SkASSERT(pictureID != SK_InvalidGenID);
return fLayerHash.find(GrCachedLayer::Key(pictureID, initialMat, key, keySize));
}
const SkIRect& srcIR,
const SkIRect& dstIR,
const SkMatrix& initialMat,
- const unsigned* key,
+ const int* key,
int keySize,
const SkPaint* paint) {
SkASSERT(pictureID != SK_InvalidGenID && start >= 0 && stop > 0);
pictInfo->incPlotUsage(plot->id());
#endif
// The layer was successfully added to the atlas
- const SkIRect bounds = SkIRect::MakeXYWH(loc.fX, loc.fY,
+ const SkIRect bounds = SkIRect::MakeXYWH(loc.fX, loc.fY,
desc.fWidth, desc.fHeight);
layer->setTexture(fAtlas->getTexture(), bounds);
layer->setPlot(plot);
static uint32_t Hash(const uint32_t& key) { return SkChecksum::Mix(key); }
// GrPictureInfo proper
- GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) {
+ GrPictureInfo(uint32_t pictureID) : fPictureID(pictureID) {
#if !GR_CACHE_HOISTED_LAYERS
- memset(fPlotUses, 0, sizeof(fPlotUses));
+ memset(fPlotUses, 0, sizeof(fPlotUses));
#endif
}
fPlotUses[plotID]--;
}
- int plotUsage(int plotID) const {
+ int plotUsage(int plotID) const {
SkASSERT(plotID < kNumPlots);
return fPlotUses[plotID];
}
// GrCachedLayer encapsulates the caching information for a single saveLayer.
//
// Atlased layers get a ref to the backing GrTexture while non-atlased layers
-// get a ref to the GrTexture in which they reside. In both cases 'fRect'
+// get a ref to the GrTexture in which they reside. In both cases 'fRect'
// contains the layer's extent in its texture.
// Atlased layers also get a pointer to the plot in which they reside.
// For non-atlased layers, the lock field just corresponds to locking in
public:
// For SkTDynamicHash
struct Key {
- Key(uint32_t pictureID, const SkMatrix& initialMat,
- const unsigned* key, int keySize, bool copyKey = false)
- : fKeySize(keySize)
+ Key(uint32_t pictureID, const SkMatrix& initialMat,
+ const int* key, int keySize, bool copyKey = false)
+ : fKeySize(keySize)
, fFreeKey(copyKey) {
fIDMatrix.fPictureID = pictureID;
fIDMatrix.fInitialMat = initialMat;
fIDMatrix.fInitialMat.getType(); // force initialization of type so hashes match
if (copyKey) {
- unsigned* tempKey = SkNEW_ARRAY(unsigned, keySize);
- memcpy(tempKey, key, keySize*sizeof(unsigned));
+ int* tempKey = SkNEW_ARRAY(int, keySize);
+ memcpy(tempKey, key, keySize*sizeof(int));
fKey = tempKey;
} else {
fKey = key;
uint32_t pictureID() const { return fIDMatrix.fPictureID; }
// TODO: remove these when GrCachedLayer & ReplacementInfo fuse
- const unsigned* key() const { SkASSERT(fFreeKey); return fKey; }
+ const int* key() const { SkASSERT(fFreeKey); return fKey; }
int keySize() const { SkASSERT(fFreeKey); return fKeySize; }
uint32_t hash() const {
uint32_t hash = SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(fKey),
fKeySize * sizeof(int));
- return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&fIDMatrix),
+ return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&fIDMatrix),
sizeof(IDMatrix), hash);
}
SkMatrix fInitialMat;
} fIDMatrix;
- const unsigned* fKey;
- const int fKeySize;
- bool fFreeKey;
+ const int* fKey;
+ const int fKeySize;
+ bool fFreeKey;
};
static const Key& GetKey(const GrCachedLayer& layer) { return layer.fKey; }
static uint32_t Hash(const Key& key) { return key.hash(); }
// GrCachedLayer proper
- GrCachedLayer(uint32_t pictureID, unsigned start, unsigned stop,
+ GrCachedLayer(uint32_t pictureID, int start, int stop,
const SkIRect& srcIR, const SkIRect& dstIR,
const SkMatrix& ctm,
- const unsigned* key, int keySize,
+ const int* key, int keySize,
const SkPaint* paint)
: fKey(pictureID, ctm, key, keySize, true)
, fStart(start)
uint32_t pictureID() const { return fKey.pictureID(); }
// TODO: remove these when GrCachedLayer & ReplacementInfo fuse
- const unsigned* key() const { return fKey.key(); }
+ const int* key() const { return fKey.key(); }
int keySize() const { return fKey.keySize(); }
- unsigned start() const { return fStart; }
+ int start() const { return fStart; }
// TODO: make bound debug only
const SkIRect& srcIR() const { return fSrcIR; }
const SkIRect& dstIR() const { return fDstIR; }
- unsigned stop() const { return fStop; }
+ int stop() const { return fStop; }
void setTexture(GrTexture* texture, const SkIRect& rect) {
SkRefCnt_SafeAssign(fTexture, texture);
fRect = rect;
const Key fKey;
// The "saveLayer" operation index of the cached layer
- const unsigned fStart;
+ const int fStart;
// The final "restore" operation index of the cached layer
- const unsigned fStop;
+ const int fStop;
// The layer's src rect (i.e., the portion of the source scene required
// for filtering).
void freeAll();
GrCachedLayer* findLayer(uint32_t pictureID, const SkMatrix& ctm,
- const unsigned* key, int keySize);
+ const int* key, int keySize);
GrCachedLayer* findLayerOrCreate(uint32_t pictureID,
- int start, int stop,
+ int start, int stop,
const SkIRect& srcIR,
const SkIRect& dstIR,
const SkMatrix& initialMat,
- const unsigned* key, int keySize,
+ const int* key, int keySize,
const SkPaint* paint);
// Attempt to place 'layer' in the atlas. Return true on success; false on failure.
// We cache this information here (rather then, say, on the owning picture)
// because we want to be able to clean it up as needed (e.g., if a picture
- // is leaked and never cleans itself up we still want to be able to
+ // is leaked and never cleans itself up we still want to be able to
// remove the GrPictureInfo once its layers are purged from all the atlas
// plots).
SkTDynamicHash<GrPictureInfo, uint32_t> fPictureHash;
GrCachedLayer* createLayer(uint32_t pictureID, int start, int stop,
const SkIRect& srcIR, const SkIRect& dstIR,
const SkMatrix& initialMat,
- const unsigned* key, int keySize,
+ const int* key, int keySize,
const SkPaint* paint);
// Remove all the layers (and unlock any resources) associated with 'pictureID'
const SkBigPicture* picture,
const SkMatrix& initialMatrix,
SkPicture::AbortCallback* callback,
- const unsigned* opIndices, int numIndices)
+ const int* opIndices, int numIndices)
: INHERITED(canvas, drawablePicts, NULL, drawableCount)
, fCanvas(canvas)
, fLayerCache(layerCache)
// For a saveLayer command, check if it can be replaced by a drawBitmap
// call and, if so, draw it and then update the current op index accordingly.
- unsigned startOffset;
+ int startOffset;
if (fOps.count()) {
startOffset = fOps[fIndex];
} else {
const SkMatrix fInitialMatrix;
SkPicture::AbortCallback* fCallback;
- SkTDArray<unsigned> fOps;
+ SkTDArray<int> fOps;
int fIndex;
int fNumReplaced;
// The op code indices of all the enclosing drawPicture and saveLayer calls
- SkTDArray<unsigned> fOpIndexStack;
+ SkTDArray<int> fOpIndexStack;
typedef Draw INHERITED;
};
class TestingAccess {
public:
- static unsigned NumLayers(GrLayerCache* cache) {
+ static int NumLayers(GrLayerCache* cache) {
return cache->numLayers();
}
static void Purge(GrLayerCache* cache, uint32_t pictureID) {
return layer->uses();
}
static GrCachedLayer* Find(GrLayerCache* cache, uint32_t pictureID,
- const SkMatrix& initialMat,
- const unsigned* key, int keySize) {
+ const SkMatrix& initialMat,
+ const int* key, int keySize) {
return cache->findLayer(pictureID, initialMat, key, keySize);
}
};
static void create_layers(skiatest::Reporter* reporter,
GrLayerCache* cache,
const SkPicture& picture,
- unsigned numToAdd,
- unsigned idOffset) {
+ int numToAdd,
+ int idOffset) {
- for (unsigned i = 0; i < numToAdd; ++i) {
- unsigned indices[1] = { idOffset+i+1 };
- GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(),
- idOffset+i+1, idOffset+i+2,
+ for (int i = 0; i < numToAdd; ++i) {
+ int indices[1] = { idOffset+i+1 };
+ GrCachedLayer* layer = cache->findLayerOrCreate(picture.uniqueID(),
+ idOffset+i+1, idOffset+i+2,
SkIRect::MakeEmpty(),
SkIRect::MakeEmpty(),
SkMatrix::I(),
indices, 1,
NULL);
REPORTER_ASSERT(reporter, layer);
- GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkMatrix::I(),
+ GrCachedLayer* temp = TestingAccess::Find(cache, picture.uniqueID(), SkMatrix::I(),
indices, 1);
REPORTER_ASSERT(reporter, temp == layer);
// locking & unlocking textures).
// TODO: need to add checks on VRAM usage!
DEF_GPUTEST(GpuLayerCache, reporter, factory) {
- static const unsigned kInitialNumLayers = 5;
+ static const int kInitialNumLayers = 5;
for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
create_layers(reporter, &cache, *picture, kInitialNumLayers, 0);
- for (unsigned i = 0; i < kInitialNumLayers; ++i) {
- unsigned indices[1] = { i + 1 };
+ for (int i = 0; i < kInitialNumLayers; ++i) {
+ int indices[1] = { i + 1 };
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
indices, 1);
REPORTER_ASSERT(reporter, layer);
}
// Unlock the textures
- for (unsigned i = 0; i < kInitialNumLayers; ++i) {
- unsigned indices[1] = { i+1 };
+ for (int i = 0; i < kInitialNumLayers; ++i) {
+ int indices[1] = { i+1 };
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
indices, 1);
cache.removeUse(layer);
}
- for (unsigned i = 0; i < kInitialNumLayers; ++i) {
- unsigned indices[1] = { i+1 };
+ for (int i = 0; i < kInitialNumLayers; ++i) {
+ int indices[1] = { i+1 };
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
indices, 1);
}
{
- unsigned indices[1] = { kInitialNumLayers+1 };
+ int indices[1] = { kInitialNumLayers+1 };
- // Add an additional layer. Since all the layers are unlocked this
+ // Add an additional layer. Since all the layers are unlocked this
// will force out the first atlased layer
create_layers(reporter, &cache, *picture, 1, kInitialNumLayers);
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
cache.removeUse(layer);
}
- for (unsigned i = 0; i < kInitialNumLayers+1; ++i) {
- unsigned indices[1] = { i+1 };
+ for (int i = 0; i < kInitialNumLayers+1; ++i) {
+ int indices[1] = { i+1 };
GrCachedLayer* layer = TestingAccess::Find(&cache, picture->uniqueID(), SkMatrix::I(),
indices, 1);
CountingBBH(const SkRect& bound) : searchCalls(0), rootBound(bound) {}
- void search(const SkRect& query, SkTDArray<unsigned>* results) const override {
+ void search(const SkRect& query, SkTDArray<int>* results) const override {
this->searchCalls++;
}
return rect;
}
-static bool verify_query(SkRect query, SkRect rects[], SkTDArray<unsigned>& found) {
- SkTDArray<unsigned> expected;
+static bool verify_query(SkRect query, SkRect rects[], SkTDArray<int>& found) {
+ SkTDArray<int> expected;
// manually intersect with every rectangle
for (int i = 0; i < NUM_RECTS; ++i) {
if (SkRect::Intersects(query, rects[i])) {
static void run_queries(skiatest::Reporter* reporter, SkRandom& rand, SkRect rects[],
const SkRTree& tree) {
for (size_t i = 0; i < NUM_QUERIES; ++i) {
- SkTDArray<unsigned> hits;
+ SkTDArray<int> hits;
SkRect query = random_rect(rand);
tree.search(query, &hits);
REPORTER_ASSERT(reporter, verify_query(query, rects, hits));
void insert(const SkRect boundsArray[], int N) override {
fEntries.setCount(N);
for (int i = 0; i < N; i++) {
- Entry e = { (unsigned)i, boundsArray[i] };
+ Entry e = { i, boundsArray[i] };
fEntries[i] = e;
}
}
- void search(const SkRect& query, SkTDArray<unsigned>* results) const override {}
+ void search(const SkRect& query, SkTDArray<int>* results) const override {}
size_t bytesUsed() const override { return 0; }
SkRect getRootBound() const override { return SkRect::MakeEmpty(); }
struct Entry {
- unsigned opIndex;
+ int opIndex;
SkRect bounds;
};
SkTDArray<Entry> fEntries;
REPORTER_ASSERT(r, bbh.fEntries.count() == 5);
for (int i = 0; i < bbh.fEntries.count(); i++) {
- REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == (unsigned)i);
+ REPORTER_ASSERT(r, bbh.fEntries[i].opIndex == i);
REPORTER_ASSERT(r, sloppy_rect_eq(SkRect::MakeWH(400, 480), bbh.fEntries[i].bounds));
}
recorder.restore();
SkRecordNoopSaveRestores(&record);
- for (unsigned i = 0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
assert_type<SkRecords::NoOp>(r, record, i);
}
}
recorder.restore();
SkRecordNoopSaveRestores(&record);
- for (unsigned index = 0; index < record.count(); index++) {
+ for (int index = 0; index < record.count(); index++) {
assert_type<SkRecords::NoOp>(r, record, index);
}
}
static void assert_savelayer_restore(skiatest::Reporter* r,
SkRecord* record,
- unsigned i,
+ int i,
bool shouldBeNoOped) {
SkRecordNoopSaveLayerDrawRestores(record);
if (shouldBeNoOped) {
static void assert_merge_svg_opacity_and_filter_layers(skiatest::Reporter* r,
SkRecord* record,
- unsigned i,
+ int i,
bool shouldBeNoOped) {
SkRecordMergeSvgOpacityAndFilterLayers(record);
if (shouldBeNoOped) {
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#include "Test.h"
#include "SkRecord.h"
}
// We should match only at 0 and 3. Going over the length should fail gracefully.
- for (unsigned i = 0; i < 8; i++) {
+ for (int i = 0; i < 8; i++) {
if (i == 0 || i == 3) {
REPORTER_ASSERT(r, pattern.match(&record, i) == i + 3);
} else {
SkRecord record;
SkRecorder recorder(&record, 1920, 1200);
- unsigned start, begin, end;
+ int start, begin, end;
start = record.count();
recorder.save();
pic.reset(recorder.endRecording());
}
- unsigned key[1] = { 0 };
+ int key[1] = { 0 };
SkPaint paint;
GrLayerCache* layerCache = context->getLayerCache();
}
}
-DEF_GPUTEST(RecordReplaceDraw, r, factory) {
+DEF_GPUTEST(RecordReplaceDraw, r, factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
if (!GrContextFactory::IsRenderingGLContext(glType)) {
int area() const { return fArea; }
void apply(const SkRecord& record) {
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
record.visit<void>(i, *this);
}
}
}
void apply(SkRecord* record) {
- for (unsigned i = 0; i < record->count(); i++) {
+ for (int i = 0; i < record->count(); i++) {
record->mutate<void>(i, *this);
}
}
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef RecordTestUtils_DEFINED
#define RecordTestUtils_DEFINED
// Assert that the ith command in record is of type T, and return it.
template <typename T>
-static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, unsigned index) {
+static const T* assert_type(skiatest::Reporter* r, const SkRecord& record, int index) {
ReadAs<T> reader;
record.visit<void>(index, reader);
REPORTER_ASSERT(r, T::kType == reader.type);
template <typename DrawT> int count_instances_of_type(const SkRecord& record) {
MatchType<DrawT> matcher;
int counter = 0;
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
counter += record.visit<int>(i, matcher);
}
return counter;
template <typename DrawT> int find_first_instances_of_type(const SkRecord& record) {
MatchType<DrawT> matcher;
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
if (record.visit<int>(i, matcher)) {
return i;
}
int count() const { return fHistogram[T::kType]; }
void apply(const SkRecord& record) {
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
record.visit<void>(i, *this);
}
}
SkCanvas* canvas,
bool timeWithCommand) {
Dumper dumper(canvas, record.count(), timeWithCommand);
- for (unsigned i = 0; i < record.count(); i++) {
+ for (int i = 0; i < record.count(); i++) {
record.visit<void>(i, dumper);
}
}