unsigned -> int for counts and indices in picture-related code
also, (C)
BUG=skia:
Review URL: https://codereview.chromium.org/1300163002
diff --git a/src/core/SkBBoxHierarchy.h b/src/core/SkBBoxHierarchy.h
index 69fb4fd..795406f 100644
--- a/src/core/SkBBoxHierarchy.h
+++ b/src/core/SkBBoxHierarchy.h
@@ -30,14 +30,14 @@
/**
* 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;
};
diff --git a/src/core/SkBigPicture.cpp b/src/core/SkBigPicture.cpp
index 6609586..bbe9882 100644
--- a/src/core/SkBigPicture.cpp
+++ b/src/core/SkBigPicture.cpp
@@ -43,8 +43,8 @@
}
void SkBigPicture::partialPlayback(SkCanvas* canvas,
- unsigned start,
- unsigned stop,
+ int start,
+ int stop,
const SkMatrix& initialCTM) const {
SkASSERT(canvas);
SkRecordPartialDraw(*fRecord,
@@ -86,7 +86,7 @@
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);
diff --git a/src/core/SkBigPicture.h b/src/core/SkBigPicture.h
index 14e413b..b7da09e 100644
--- a/src/core/SkBigPicture.h
+++ b/src/core/SkBigPicture.h
@@ -52,8 +52,8 @@
// 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; }
diff --git a/src/core/SkLayerInfo.h b/src/core/SkLayerInfo.h
index 3d4b269..54c4f7b 100644
--- a/src/core/SkLayerInfo.h
+++ b/src/core/SkLayerInfo.h
@@ -56,8 +56,8 @@
// 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() {}
diff --git a/src/core/SkRTree.cpp b/src/core/SkRTree.cpp
index 2fded6f..bae2fdc 100644
--- a/src/core/SkRTree.cpp
+++ b/src/core/SkRTree.cpp
@@ -161,13 +161,13 @@
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) {
diff --git a/src/core/SkRTree.h b/src/core/SkRTree.h
index 205c0b6..5578171 100644
--- a/src/core/SkRTree.h
+++ b/src/core/SkRTree.h
@@ -31,7 +31,7 @@
*/
class SkRTree : public SkBBoxHierarchy {
public:
-
+
/**
* If you have some prior information about the distribution of bounds you're expecting, you
@@ -42,7 +42,7 @@
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.
@@ -65,7 +65,7 @@
struct Branch {
union {
Node* fSubtree;
- unsigned fOpIndex;
+ int fOpIndex;
};
SkRect fBounds;
};
@@ -76,7 +76,7 @@
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);
diff --git a/src/core/SkRecord.cpp b/src/core/SkRecord.cpp
index 349fbf6..2d2fa58 100644
--- a/src/core/SkRecord.cpp
+++ b/src/core/SkRecord.cpp
@@ -9,7 +9,7 @@
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);
}
}
diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h
index 0fe316e..9672bbc 100644
--- a/src/core/SkRecord.h
+++ b/src/core/SkRecord.h
@@ -40,14 +40,14 @@
~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);
}
@@ -57,7 +57,7 @@
// 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);
}
@@ -85,7 +85,7 @@
// 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;
@@ -98,7 +98,7 @@
// 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());
@@ -186,7 +186,7 @@
// 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
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 8c884d9..890a0bf 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -29,7 +29,7 @@
query.setEmpty();
}
- SkTDArray<unsigned> ops;
+ SkTDArray<int> ops;
bbh->search(query, &ops);
SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount);
@@ -45,7 +45,7 @@
} 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;
}
@@ -59,13 +59,13 @@
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);
}
}
@@ -161,7 +161,7 @@
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
@@ -190,9 +190,9 @@
// 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 {
@@ -574,7 +574,7 @@
return true;
}
- const unsigned fNumRecords;
+ const int fNumRecords;
// We do not guarantee anything for operations outside of the cull rect
const SkRect fCullRect;
@@ -585,13 +585,13 @@
// 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.
@@ -605,7 +605,7 @@
, 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
@@ -696,10 +696,10 @@
// 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));
}
}
@@ -773,8 +773,8 @@
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();
}
@@ -783,7 +783,7 @@
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;
@@ -795,7 +795,7 @@
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);
}
@@ -808,7 +808,7 @@
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);
}
diff --git a/src/core/SkRecordDraw.h b/src/core/SkRecordDraw.h
index 5b248cf..5af74dc 100644
--- a/src/core/SkRecordDraw.h
+++ b/src/core/SkRecordDraw.h
@@ -36,7 +36,7 @@
// 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 {
diff --git a/src/core/SkRecordOpts.cpp b/src/core/SkRecordOpts.cpp
index 8351292..07aac3e 100644
--- a/src/core/SkRecordOpts.cpp
+++ b/src/core/SkRecordOpts.cpp
@@ -26,7 +26,7 @@
// 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.
@@ -36,7 +36,7 @@
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);
@@ -51,7 +51,7 @@
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;
@@ -127,9 +127,9 @@
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;
@@ -148,7 +148,7 @@
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) {
@@ -170,7 +170,7 @@
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;
@@ -195,7 +195,7 @@
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.
@@ -219,7 +219,7 @@
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;
diff --git a/src/core/SkRecordPattern.h b/src/core/SkRecordPattern.h
index 85c38ac..174665a 100644
--- a/src/core/SkRecordPattern.h
+++ b/src/core/SkRecordPattern.h
@@ -1,3 +1,10 @@
+/*
+ * 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
@@ -109,14 +116,14 @@
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) {
@@ -137,7 +144,7 @@
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;
@@ -148,7 +155,7 @@
// 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;
@@ -168,7 +175,7 @@
// 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
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index c00a353..b12b1eb 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -245,7 +245,7 @@
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),
@@ -255,7 +255,7 @@
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),