Fix a bunch of warnings, mainly around rowBytes.

My recent change changed the way SkBitmap::fRowBytes is stored,
and parameter/return values referring to rowBytes were changed
to type size_t. Change the storage back, and eliminate warnings
resulting from returning a size_t.

Review URL: https://codereview.appspot.com/7396059

git-svn-id: http://skia.googlecode.com/svn/trunk@7855 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2013-02-25 21:47:41 +00:00
parent 10863051df
commit e5f48243bd
20 changed files with 62 additions and 60 deletions

View File

@ -645,7 +645,7 @@ private:
kImageIsImmutable_Flag = 0x04
};
size_t fRowBytes;
uint32_t fRowBytes;
uint32_t fWidth;
uint32_t fHeight;
uint8_t fConfig;

View File

@ -47,7 +47,7 @@ struct SkBitmap::MipMap : SkNoncopyable {
Sk64 size;
size.setMul(levelCount + 1, sizeof(MipLevel));
size.add(sizeof(MipMap));
size.add(pixelSize);
size.add(SkToS32(pixelSize));
if (!isPos32Bits(size)) {
return NULL;
}
@ -220,7 +220,7 @@ size_t SkBitmap::ComputeRowBytes(Config c, int width) {
Sk64 SkBitmap::ComputeSize64(Config c, int width, int height) {
Sk64 size;
size.setMul(SkBitmap::ComputeRowBytes(c, width), height);
size.setMul(SkToS32(SkBitmap::ComputeRowBytes(c, width)), height);
return size;
}
@ -236,9 +236,11 @@ Sk64 SkBitmap::ComputeSafeSize64(Config config,
Sk64 safeSize;
safeSize.setZero();
if (height > 0) {
safeSize.set(ComputeRowBytes(config, width));
// TODO: Handle the case where the return value from
// ComputeRowBytes is more than 31 bits.
safeSize.set(SkToS32(ComputeRowBytes(config, width)));
Sk64 sizeAllButLastRow;
sizeAllButLastRow.setMul(height - 1, rowBytes);
sizeAllButLastRow.setMul(height - 1, SkToS32(rowBytes));
safeSize.add(sizeAllButLastRow);
}
SkASSERT(!safeSize.isNeg());
@ -283,7 +285,7 @@ void SkBitmap::setConfig(Config c, int width, int height, size_t rowBytes) {
fConfig = SkToU8(c);
fWidth = width;
fHeight = height;
fRowBytes = rowBytes;
fRowBytes = SkToU32(rowBytes);
fBytesPerPixel = (uint8_t)ComputeBytesPerPixel(c);
@ -496,7 +498,7 @@ bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize,
return false;
else {
// Just copy what we need on each line.
uint32_t rowBytes = ComputeRowBytes(getConfig(), fWidth);
size_t rowBytes = ComputeRowBytes(getConfig(), fWidth);
SkAutoLockPixels lock(*this);
const uint8_t* srcP = reinterpret_cast<const uint8_t*>(getPixels());
uint8_t* dstP = reinterpret_cast<uint8_t*>(dst);
@ -864,7 +866,7 @@ static size_t getSubOffset(const SkBitmap& bm, int x, int y) {
* upper left corner of bm relative to its SkPixelRef.
* x and y must be non-NULL.
*/
static bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y) {
static bool getUpperLeftFromOffset(const SkBitmap& bm, int32_t* x, int32_t* y) {
SkASSERT(x != NULL && y != NULL);
const size_t offset = bm.pixelRefOffset();
if (0 == offset) {
@ -872,9 +874,9 @@ static bool getUpperLeftFromOffset(const SkBitmap& bm, int* x, int* y) {
return true;
}
// Use integer division to find the correct y position.
*y = offset / bm.rowBytes();
*y = SkToS32(offset / bm.rowBytes());
// The remainder will be the x position, after we reverse getSubOffset.
*x = offset % bm.rowBytes();
*x = SkToS32(offset % bm.rowBytes());
switch (bm.getConfig()) {
case SkBitmap::kA8_Config:
// Fall through.
@ -948,7 +950,7 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
const RLEPixels* rle = (const RLEPixels*)this->getPixels();
uint8_t* dst = bm.getAddr8(0, 0);
const int width = bm.width();
const int rowBytes = bm.rowBytes();
const size_t rowBytes = bm.rowBytes();
for (int y = r.fTop; y < r.fBottom; y++) {
SkPackBits::Unpack8(dst, r.fLeft, width, rle->packedAtY(y));
@ -1141,7 +1143,7 @@ bool SkBitmap::deepCopyTo(SkBitmap* dst, Config dstConfig) const {
} else {
// Find the correct offset in the new config. This needs to be done after calling
// setConfig so dst's fConfig and fRowBytes have been set properly.
int x, y;
int32_t x, y;
if (!getUpperLeftFromOffset(*this, &x, &y)) {
return false;
}
@ -1335,13 +1337,13 @@ void SkBitmap::buildMipMap(bool forceRebuild) {
uint8_t* addr = (uint8_t*)mm->pixels();
int width = this->width();
int height = this->height();
unsigned rowBytes;
uint32_t rowBytes;
SkBitmap dstBM;
for (int i = 0; i < maxLevels; i++) {
width >>= 1;
height >>= 1;
rowBytes = ComputeRowBytes(config, width);
rowBytes = SkToU32(ComputeRowBytes(config, width));
level[i].fPixels = addr;
level[i].fWidth = width;
@ -1417,7 +1419,7 @@ static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha,
SkBitmap::Config config = src.getConfig();
int w = src.width();
int h = src.height();
int rb = src.rowBytes();
size_t rb = src.rowBytes();
SkAutoLockPixels alp(src);
if (!src.readyToDraw()) {
@ -1561,7 +1563,7 @@ void SkBitmap::flatten(SkFlattenableWriteBuffer& buffer) const {
if (fPixelRef) {
if (fPixelRef->getFactory()) {
buffer.writeInt(SERIALIZE_PIXELTYPE_REF_DATA);
buffer.writeUInt(fPixelRefOffset);
buffer.writeUInt(SkToU32(fPixelRefOffset));
buffer.writeFlattenable(fPixelRef);
return;
}

View File

@ -49,12 +49,12 @@ void MAKENAME(_nofilter_DXDY)(const SkBitmapProcState& s,
PREAMBLE(s);
#endif
const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
int i, rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
uint32_t XY;
SRCTYPE src;
for (i = (count >> 1); i > 0; --i) {
for (int i = (count >> 1); i > 0; --i) {
XY = *xy++;
SkASSERT((XY >> 16) < (unsigned)s.fBitmap->height() &&
(XY & 0xFFFF) < (unsigned)s.fBitmap->width());
@ -146,7 +146,7 @@ void MAKENAME(_filter_DX)(const SkBitmapProcState& s,
PREAMBLE(s);
#endif
const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
unsigned rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
unsigned subY;
const SRCTYPE* SK_RESTRICT row0;
const SRCTYPE* SK_RESTRICT row1;
@ -192,7 +192,7 @@ void MAKENAME(_filter_DXDY)(const SkBitmapProcState& s,
PREAMBLE(s);
#endif
const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
int rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
do {
uint32_t data = *xy++;

View File

@ -44,7 +44,7 @@ void SCALE_FILTER_NAME(const SkBitmapProcState& s, int x, int y,
int y1 = TILEY_PROCF((fy + s.fFilterOneY), maxY);
const char* SK_RESTRICT srcAddr = (const char*)s.fBitmap->getPixels();
unsigned rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
row0 = (const SRCTYPE*)(srcAddr + y0 * rb);
row1 = (const SRCTYPE*)(srcAddr + y1 * rb);
// now initialize fx

View File

@ -82,7 +82,7 @@ bool SkBitmap::scrollRect(const SkIRect* subset, int dx, int dy,
char* dst = (char*)this->getPixels();
const char* src = dst;
int rowBytes = this->rowBytes(); // need rowBytes to be signed
int rowBytes = (int)this->rowBytes(); // need rowBytes to be signed
if (dy <= 0) {
src -= dy * rowBytes;

View File

@ -31,7 +31,7 @@ static void SK_BLITBWMASK_NAME(const SkBitmap& bitmap, const SkMask& srcMask, co
int cy = clip.fTop;
int maskLeft = srcMask.fBounds.fLeft;
unsigned mask_rowBytes = srcMask.fRowBytes;
unsigned bitmap_rowBytes = bitmap.rowBytes();
size_t bitmap_rowBytes = bitmap.rowBytes();
unsigned height = clip.height();
SkASSERT(mask_rowBytes != 0);

View File

@ -156,7 +156,7 @@ void SkARGB4444_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
SkPMColor16* device = fDevice.getAddr16(x, y);
SkPMColor16 color = fPMColor16;
SkPMColor16 other = fPMColor16Other;
unsigned rb = fDevice.rowBytes();
size_t rb = fDevice.rowBytes();
if ((x ^ y) & 1) {
SkTSwap<SkPMColor16>(color, other);
@ -337,7 +337,7 @@ void SkARGB4444_Blitter::blitMask(const SkMask& mask, const SkIRect& clip) {
SkPMColor16* device = fDevice.getAddr16(x, y);
const uint8_t* alpha = mask.getAddr8(x, y);
SkPMColor16 srcColor = fPMColor16;
unsigned devRB = fDevice.rowBytes() - (width << 1);
size_t devRB = fDevice.rowBytes() - (width << 1);
unsigned maskRB = mask.fRowBytes - width;
do {

View File

@ -180,7 +180,7 @@ void SkA8_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
unsigned sa = SkAlphaMul(fSrcA, SkAlpha255To256(alpha));
uint8_t* device = fDevice.getAddr8(x, y);
int rowBytes = fDevice.rowBytes();
size_t rowBytes = fDevice.rowBytes();
if (sa == 0xFF) {
for (int i = 0; i < height; i++) {

View File

@ -196,7 +196,7 @@ void SkARGB32_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
}
unsigned dst_scale = 255 - SkGetPackedA32(color);
uint32_t rowBytes = fDevice.rowBytes();
size_t rowBytes = fDevice.rowBytes();
while (--height >= 0) {
device[0] = color + SkAlphaMulQ(device[0], dst_scale);
device = (uint32_t*)((char*)device + rowBytes);

View File

@ -211,7 +211,7 @@ void SkRGB16_Black_Blitter::blitMask(const SkMask& mask,
const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop);
unsigned width = clip.width();
unsigned height = clip.height();
unsigned deviceRB = fDevice.rowBytes() - (width << 1);
size_t deviceRB = fDevice.rowBytes() - (width << 1);
unsigned maskRB = mask.fRowBytes - width;
SkASSERT((int)height > 0);
@ -381,7 +381,7 @@ void SkRGB16_Opaque_Blitter::blitMask(const SkMask& mask,
const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop);
int width = clip.width();
int height = clip.height();
unsigned deviceRB = fDevice.rowBytes() - (width << 1);
size_t deviceRB = fDevice.rowBytes() - (width << 1);
unsigned maskRB = mask.fRowBytes - width;
uint32_t expanded32 = fExpandedRaw16;
@ -481,7 +481,7 @@ void SkRGB16_Opaque_Blitter::blitMask(const SkMask& mask,
void SkRGB16_Opaque_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
unsigned deviceRB = fDevice.rowBytes();
size_t deviceRB = fDevice.rowBytes();
// TODO: respect fDoDither
unsigned scale5 = SkAlpha255To256(alpha) >> 3;
@ -497,7 +497,7 @@ void SkRGB16_Opaque_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
void SkRGB16_Opaque_Blitter::blitRect(int x, int y, int width, int height) {
SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height());
uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
unsigned deviceRB = fDevice.rowBytes();
size_t deviceRB = fDevice.rowBytes();
uint16_t color16 = fColor16;
if (fDoDither) {
@ -641,7 +641,7 @@ void SkRGB16_Blitter::blitMask(const SkMask& mask,
const uint8_t* SK_RESTRICT alpha = mask.getAddr8(clip.fLeft, clip.fTop);
int width = clip.width();
int height = clip.height();
unsigned deviceRB = fDevice.rowBytes() - (width << 1);
size_t deviceRB = fDevice.rowBytes() - (width << 1);
unsigned maskRB = mask.fRowBytes - width;
uint32_t color32 = fExpandedRaw16;
@ -662,7 +662,7 @@ void SkRGB16_Blitter::blitMask(const SkMask& mask,
void SkRGB16_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
unsigned deviceRB = fDevice.rowBytes();
size_t deviceRB = fDevice.rowBytes();
// TODO: respect fDoDither
unsigned scale5 = SkAlpha255To256(alpha) * fScale >> (8 + 3);
@ -678,7 +678,7 @@ void SkRGB16_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) {
SkASSERT(x + width <= fDevice.width() && y + height <= fDevice.height());
uint16_t* SK_RESTRICT device = fDevice.getAddr16(x, y);
unsigned deviceRB = fDevice.rowBytes();
size_t deviceRB = fDevice.rowBytes();
SkPMColor src32 = fSrcColor32;
while (--height >= 0) {

View File

@ -354,7 +354,7 @@ static void bw_pt_rect_16_hair_proc(const PtProcRec& rec,
SkASSERT(bitmap);
uint16_t* addr = bitmap->getAddr16(0, 0);
int rb = bitmap->rowBytes();
size_t rb = bitmap->rowBytes();
for (int i = 0; i < count; i++) {
int x = SkScalarFloorToInt(devPts[i].fX);
@ -375,7 +375,7 @@ static void bw_pt_rect_32_hair_proc(const PtProcRec& rec,
SkASSERT(bitmap);
SkPMColor* addr = bitmap->getAddr32(0, 0);
int rb = bitmap->rowBytes();
size_t rb = bitmap->rowBytes();
for (int i = 0; i < count; i++) {
int x = SkScalarFloorToInt(devPts[i].fX);
@ -1161,7 +1161,7 @@ void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap,
SkMask mask;
mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height());
mask.fFormat = SkMask::kA8_Format;
mask.fRowBytes = bitmap.rowBytes();
mask.fRowBytes = SkToU32(bitmap.rowBytes());
mask.fImage = bitmap.getAddr8(0, 0);
this->drawDevMask(mask, paint);

View File

@ -89,7 +89,7 @@ int32_t SkOrderedReadBuffer::read32() {
char* SkOrderedReadBuffer::readString() {
const char* string = fReader.readString();
const int32_t length = strlen(string);
const size_t length = strlen(string);
char* value = (char*)sk_malloc_throw(length + 1);
strcpy(value, string);
return value;

View File

@ -22,8 +22,8 @@ public:
SkSPRITE_DST_TYPE* SK_RESTRICT dst =fDevice->SkSPRITE_DST_GETADDR(x, y);
const SkSPRITE_SRC_TYPE* SK_RESTRICT src =
fSource->SkSPRITE_SRC_GETADDR(srcX, srcY);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
SkDEBUGCODE((void)fDevice->SkSPRITE_DST_GETADDR(x + width - 1, y + height - 1);)
SkDEBUGCODE((void)fSource->SkSPRITE_SRC_GETADDR(srcX + width - 1, srcY + height - 1);)

View File

@ -127,8 +127,8 @@ public:
uint32_t* SK_RESTRICT dst = fDevice->getAddr32(x, y);
const uint32_t* SK_RESTRICT src = fSource->getAddr32(x - fLeft,
y - fTop);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
SkColorFilter* colorFilter = fColorFilter;
SkXfermode* xfermode = fXfermode;
@ -174,8 +174,8 @@ public:
SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y);
const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft,
y - fTop);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
SkPMColor* SK_RESTRICT buffer = fBuffer;
SkColorFilter* colorFilter = fColorFilter;
SkXfermode* xfermode = fXfermode;
@ -221,8 +221,8 @@ public:
SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y);
const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft,
y - fTop);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
do {
src_row(dst, src, width);
@ -250,8 +250,8 @@ public:
SkPMColor* SK_RESTRICT dst = fDevice->getAddr32(x, y);
const SkPMColor16* SK_RESTRICT src = fSource->getAddr16(x - fLeft,
y - fTop);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
do {
srcover_row(dst, src, width);

View File

@ -58,8 +58,8 @@ public:
uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y);
const uint16_t* SK_RESTRICT src = fSource->getAddr16(x - fLeft,
y - fTop);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
while (--height >= 0) {
memcpy(dst, src, width << 1);
@ -285,8 +285,8 @@ public:
uint16_t* SK_RESTRICT dst = fDevice->getAddr16(x, y);
const SkPMColor* SK_RESTRICT src = fSource->getAddr32(x - fLeft,
y - fTop);
unsigned dstRB = fDevice->rowBytes();
unsigned srcRB = fSource->rowBytes();
size_t dstRB = fDevice->rowBytes();
size_t srcRB = fSource->rowBytes();
SkBlitRow::Proc proc = fProc;
U8CPU alpha = fPaint->getAlpha();

View File

@ -57,7 +57,7 @@ private:
// setup state
char* fDstRow; // points into bitmap's pixels
int fDstRowBytes;
size_t fDstRowBytes;
int fCurrY; // used for dithering
int fSrcPixelSize; // 1, 3, 4
RowProc fRowProc;

View File

@ -49,7 +49,7 @@ static size_t ComputeMinRowBytesAndSize(const SkImage::Info& info, size_t* rowBy
Sk64 safeSize;
safeSize.setZero();
if (info.fHeight > 0) {
safeSize.setMul(info.fHeight, *rowBytes);
safeSize.setMul(info.fHeight, SkToS32(*rowBytes));
}
SkASSERT(!safeSize.isNeg());
return safeSize.is32() ? safeSize.get32() : 0;

View File

@ -20,7 +20,7 @@ void S32_opaque_D32_filter_DX_SSE2(const SkBitmapProcState& s,
SkASSERT(s.fAlphaScale == 256);
const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
unsigned rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
uint32_t XY = *xy++;
unsigned y0 = XY >> 14;
const uint32_t* row0 = reinterpret_cast<const uint32_t*>(srcAddr + (y0 >> 4) * rb);
@ -126,7 +126,7 @@ void S32_alpha_D32_filter_DX_SSE2(const SkBitmapProcState& s,
SkASSERT(s.fAlphaScale < 256);
const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
unsigned rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
uint32_t XY = *xy++;
unsigned y0 = XY >> 14;
const uint32_t* row0 = reinterpret_cast<const uint32_t*>(srcAddr + (y0 >> 4) * rb);
@ -647,7 +647,7 @@ void S32_D16_filter_DX_SSE2(const SkBitmapProcState& s,
SkPMColor dstColor;
const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
unsigned rb = s.fBitmap->rowBytes();
size_t rb = s.fBitmap->rowBytes();
uint32_t XY = *xy++;
unsigned y0 = XY >> 14;
const uint32_t* row0 = reinterpret_cast<const uint32_t*>(srcAddr + (y0 >> 4) * rb);

View File

@ -395,7 +395,7 @@ void S32_generic_D32_filter_DX_SSSE3(const SkBitmapProcState& s,
const uint8_t* src_addr =
static_cast<const uint8_t*>(s.fBitmap->getPixels());
const unsigned rb = s.fBitmap->rowBytes();
const size_t rb = s.fBitmap->rowBytes();
const uint32_t XY = *xy++;
const unsigned y0 = XY >> 14;
const uint32_t* row0 =
@ -586,7 +586,7 @@ void S32_generic_D32_filter_DXDY_SSSE3(const SkBitmapProcState& s,
const uint8_t* src_addr =
static_cast<const uint8_t*>(s.fBitmap->getPixels());
const unsigned rb = s.fBitmap->rowBytes();
const size_t rb = s.fBitmap->rowBytes();
// vector constants
const __m128i mask_dist_select = _mm_set_epi8(12, 12, 12, 12,

View File

@ -92,7 +92,7 @@ void* ThreadSafePipeController::requestBlock(size_t minRequest, size_t *actual)
PipeBlock previousBloc(fBlock, fBytesWritten);
fBlockList.push(previousBloc);
}
int32_t blockSize = SkMax32(minRequest, kMinBlockSize);
int32_t blockSize = SkMax32(SkToS32(minRequest), kMinBlockSize);
fBlock = fAllocator.allocThrow(blockSize);
fBytesWritten = 0;
*actual = blockSize;