Beispiel #1
0
// Returns the square of the Euclidian distance to (dx,dy) in *result.
static inline void getLengthSquared(SkScalar dx, SkScalar dy, Sk64 *result) {
    Sk64    dySqr;

    result->setMul(dx, dx);
    dySqr.setMul(dy, dy);
    result->add(dySqr);
}
Beispiel #2
0
/** returns the product if it is positive and fits in 31 bits. Otherwise this
    returns 0.
 */
static int32_t safeMul32(int32_t a, int32_t b) {
    Sk64 size;
    size.setMul(a, b);
    if (size.is32() && size.isPos()) {
        return size.get32();
    }
    return 0;
}
Beispiel #3
0
 static MipMap* Alloc(int levelCount, size_t pixelSize) {
     if (levelCount < 0) {
         return NULL;
     }
     Sk64 size;
     size.setMul(levelCount + 1, sizeof(MipLevel));
     size.add(sizeof(MipMap));
     size.add(pixelSize);
     if (!isPos32Bits(size)) {
         return NULL;
     }
     MipMap* mm = (MipMap*)sk_malloc_throw(size.get32());
     mm->fRefCnt = 1;
     mm->fLevelCount = levelCount;
     return mm;
 }
SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
                                                size_t requestedRowBytes,
                                                SkColorTable* ctable) {
    if (!is_valid(info, ctable)) {
        return NULL;
    }

    int32_t minRB = info.minRowBytes();
    if (minRB < 0) {
        return NULL;    // allocation will be too large
    }
    if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) {
        return NULL;    // cannot meet requested rowbytes
    }

    int32_t rowBytes;
    if (requestedRowBytes) {
        rowBytes = requestedRowBytes;
    } else {
        rowBytes = minRB;
    }

    Sk64 bigSize;
    bigSize.setMul(info.fHeight, rowBytes);
    if (!bigSize.is32()) {
        return NULL;
    }

    size_t size = bigSize.get32();
    void* addr = sk_malloc_flags(size, 0);
    if (NULL == addr) {
        return NULL;
    }

    return SkNEW_ARGS(SkMallocPixelRef, (info, addr, rowBytes, ctable, true));
}