while (iter > stop) {
if (*--iter == elem) {
- return iter - stop;
+ return SkToInt(iter - stop);
}
}
return -1;
SkIntToScalar(kBitmapSize/4), paint);
}
+static bool valid_for_raster_canvas(const SkBitmap& bm) {
+ SkImageInfo info;
+ if (!bm.asImageInfo(&info)) {
+ return false;
+ }
+ switch (info.fColorType) {
+ case kAlpha_8_SkColorType:
+ case kRGB_565_SkColorType:
+ return true;
+ case kPMColor_SkColorType:
+ return kPremul_SkAlphaType == info.fAlphaType ||
+ kOpaque_SkAlphaType == info.fAlphaType;
+ default:
+ break;
+ }
+ return false;
+}
+
static void make_checkerboard_bitmap(SkBitmap& bitmap) {
bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
- while (!bitmap.allocPixels()) {
+ while (valid_for_raster_canvas(bitmap) && !bitmap.allocPixels()) {
bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, kBitmapSize);
}
SkBitmapDevice device(bitmap);
void SkBBoxRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) {
SkRect bbox;
- bbox.set(pts, count);
+ bbox.set(pts, SkToInt(count));
// Small min width value, just to ensure hairline point bounding boxes aren't empty.
// Even though we know hairline primitives are drawn one pixel wide, we do not use a
// minimum of 1 because the playback scale factor is unknown at record time. Later
SkData* SkValidatingSerializeFlattenable(SkFlattenable* flattenable) {
SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
writer.writeFlattenable(flattenable);
- uint32_t size = writer.bytesWritten();
+ size_t size = writer.bytesWritten();
void* data = sk_malloc_throw(size);
writer.writeToMemory(data);
return SkData::NewFromMalloc(data, size);
SkPictureStateTree::~SkPictureStateTree() {
}
-SkPictureStateTree::Draw* SkPictureStateTree::appendDraw(uint32_t offset) {
+SkPictureStateTree::Draw* SkPictureStateTree::appendDraw(size_t offset) {
Draw* draw = static_cast<Draw*>(fAlloc.allocThrow(sizeof(Draw)));
*draw = fCurrentState;
- draw->fOffset = offset;
+ draw->fOffset = SkToU32(offset);
return draw;
}
fCurrentState.fNode->fFlags |= Node::kSave_Flag;
}
-void SkPictureStateTree::appendSaveLayer(uint32_t offset) {
+void SkPictureStateTree::appendSaveLayer(size_t offset) {
*static_cast<Draw*>(fStateStack.push_back()) = fCurrentState;
this->appendNode(offset);
fCurrentState.fNode->fFlags |= Node::kSaveLayer_Flag;
fCurrentState.fMatrix = m;
}
-void SkPictureStateTree::appendClip(uint32_t offset) {
+void SkPictureStateTree::appendClip(size_t offset) {
this->appendNode(offset);
}
return Iterator(draws, canvas, &fRoot);
}
-void SkPictureStateTree::appendNode(uint32_t offset) {
+void SkPictureStateTree::appendNode(size_t offset) {
Node* n = static_cast<Node*>(fAlloc.allocThrow(sizeof(Node)));
- n->fOffset = offset;
+ n->fOffset = SkToU32(offset);
n->fFlags = 0;
n->fParent = fCurrentState.fNode;
n->fLevel = fCurrentState.fNode->fLevel + 1;
/**
* Creates and returns a struct representing a draw at the given offset.
*/
- Draw* appendDraw(uint32_t offset);
+ Draw* appendDraw(size_t offset);
/**
* Given a list of draws, and a canvas, returns an iterator that produces the correct sequence
Iterator getIterator(const SkTDArray<void*>& draws, SkCanvas* canvas);
void appendSave();
- void appendSaveLayer(uint32_t offset);
+ void appendSaveLayer(size_t offset);
void appendRestore();
void appendTransform(const SkMatrix& trans);
- void appendClip(uint32_t offset);
+ void appendClip(size_t offset);
/**
* Call this immediately after an appendRestore call that is associated
private:
- void appendNode(uint32_t offset);
+ void appendNode(size_t offset);
SkChunkAlloc fAlloc;
// Needed by saveCollapsed() because nodes do not currently store
}
void SkWriteBuffer::writeByteArray(const void* data, size_t size) {
- fWriter.write32(size);
+ fWriter.write32(SkToU32(size));
fWriter.writePad(data, size);
}
void SkWriteBuffer::writeEncodedString(const void* value, size_t byteLength,
SkPaint::TextEncoding encoding) {
fWriter.writeInt(encoding);
- fWriter.writeInt(byteLength);
+ fWriter.writeInt(SkToU32(byteLength));
fWriter.write(value, byteLength);
}
}
size_t SkWriteBuffer::writeStream(SkStream* stream, size_t length) {
- fWriter.write32(length);
+ fWriter.write32(SkToU32(length));
size_t bytesWritten = fWriter.readFromStream(stream, length);
if (bytesWritten < length) {
fWriter.reservePad(length - bytesWritten);
// make room for the size of the flattened object
(void)fWriter.reserve(sizeof(uint32_t));
// record the current size, so we can subtract after the object writes.
- uint32_t offset = fWriter.bytesWritten();
+ size_t offset = fWriter.bytesWritten();
// now flatten the object
flattenable->flatten(*this);
- uint32_t objSize = fWriter.bytesWritten() - offset;
+ size_t objSize = fWriter.bytesWritten() - offset;
// record the obj's size
- fWriter.write32At(offset - sizeof(uint32_t), objSize);
+ fWriter.write32At(offset - sizeof(uint32_t), SkToU32(objSize));
}