sk_sp<SkPixelRef> SkMallocPixelRef::MakeUsing(void*(*alloc)(size_t), const SkImageInfo& info, size_t requestedRowBytes, sk_sp<SkColorTable> ctable) { if (!is_valid(info, ctable.get())) { return nullptr; } // only want to permit 31bits of rowBytes int64_t minRB = (int64_t)info.minRowBytes64(); if (minRB < 0 || !sk_64_isS32(minRB)) { return nullptr; // allocation will be too large } if (requestedRowBytes > 0 && (int32_t)requestedRowBytes < minRB) { return nullptr; // cannot meet requested rowbytes } int32_t rowBytes; if (requestedRowBytes) { rowBytes = SkToS32(requestedRowBytes); } else { rowBytes = minRB; } int64_t bigSize = (int64_t)info.height() * rowBytes; if (!sk_64_isS32(bigSize)) { return nullptr; } size_t size = sk_64_asS32(bigSize); SkASSERT(size >= info.getSafeSize(rowBytes)); void* addr = alloc(size); if (nullptr == addr) { return nullptr; } return sk_sp<SkPixelRef>(new SkMallocPixelRef(info, addr, rowBytes, std::move(ctable), sk_free_releaseproc, nullptr)); }