diff options
author | cblume <cblume@chromium.org> | 2016-09-22 05:25:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-22 05:25:26 -0700 |
commit | 921bc678a7b81de31b4e672326ed2f37ffb66b10 (patch) | |
tree | 1659120fb2ff6edcd60c3358288218b56d032333 /src | |
parent | 02472ddc940f50068e7eb1f7d8daa7fd6e0a45c7 (diff) |
Is char* or uintptr_t easier to read?
Using a char* instead of uintptr_t allows us to use fewer
reinterpret_casts which may make the code easier to read.
BUG=648512
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2356703002
Review-Url: https://codereview.chromium.org/2356703002
Diffstat (limited to 'src')
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index f8e3b94aff..b769e0a684 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -409,16 +409,16 @@ namespace { class DTIBufferFiller { public: - explicit DTIBufferFiller(uintptr_t bufferAsInt) - : bufferAsInt_(bufferAsInt) {} + explicit DTIBufferFiller(char* bufferAsCharPtr) + : bufferAsCharPtr_(bufferAsCharPtr) {} void fillMember(const void* source, size_t memberOffset, size_t size) { - memcpy(reinterpret_cast<void*>(bufferAsInt_ + memberOffset), source, size); + memcpy(bufferAsCharPtr_ + memberOffset, source, size); } private: - uintptr_t bufferAsInt_; + char* bufferAsCharPtr_; }; } @@ -552,15 +552,16 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox if (!fillMode) { return size; } - uintptr_t bufferAsInt = reinterpret_cast<uintptr_t>(buffer); - uintptr_t pixelsAsInt = bufferAsInt + pixelOffset; - void* pixels = reinterpret_cast<void*>(pixelsAsInt); + char* bufferAsCharPtr = reinterpret_cast<char*>(buffer); + char* pixelsAsCharPtr = bufferAsCharPtr + pixelOffset; + void* pixels = pixelsAsCharPtr; void* ct = nullptr; if (ctSize) { - ct = reinterpret_cast<void*>(bufferAsInt + ctOffset); + ct = bufferAsCharPtr + ctOffset; } - memcpy(reinterpret_cast<void*>(SkAlign8(pixelsAsInt)), pixmap.addr(), pixmap.getSafeSize()); + memcpy(reinterpret_cast<void*>(SkAlign8(reinterpret_cast<uintptr_t>(pixelsAsCharPtr))), + pixmap.addr(), pixmap.getSafeSize()); if (ctSize) { memcpy(ct, pixmap.ctable()->readColors(), ctSize); } @@ -569,7 +570,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox size_t rowBytes = pixmap.rowBytes(); static_assert(std::is_standard_layout<DeferredTextureImage>::value, "offsetof, which we use below, requires the type have standard layout"); - auto dtiBufferFiller = DTIBufferFiller{bufferAsInt}; + auto dtiBufferFiller = DTIBufferFiller{bufferAsCharPtr}; FILL_MEMBER(dtiBufferFiller, fGammaTreatment, &gammaTreatment); FILL_MEMBER(dtiBufferFiller, fContextUniqueID, &proxy.fContextUniqueID); int width = info.width(); @@ -583,28 +584,24 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox FILL_MEMBER(dtiBufferFiller, fColorTableCnt, &ctCount); FILL_MEMBER(dtiBufferFiller, fColorTableData, &ct); FILL_MEMBER(dtiBufferFiller, fMipMapLevelCount, &mipMapLevelCount); - memcpy(reinterpret_cast<void*>(bufferAsInt + - offsetof(DeferredTextureImage, fMipMapLevelData[0].fPixelData)), + memcpy(bufferAsCharPtr + offsetof(DeferredTextureImage, fMipMapLevelData[0].fPixelData), &pixels, sizeof(pixels)); - memcpy(reinterpret_cast<void*>(bufferAsInt + - offsetof(DeferredTextureImage, fMipMapLevelData[0].fRowBytes)), + memcpy(bufferAsCharPtr + offsetof(DeferredTextureImage, fMipMapLevelData[0].fRowBytes), &rowBytes, sizeof(rowBytes)); if (colorSpaceSize) { - void* colorSpace = reinterpret_cast<void*>(bufferAsInt + colorSpaceOffset); + void* colorSpace = bufferAsCharPtr + colorSpaceOffset; FILL_MEMBER(dtiBufferFiller, fColorSpace, &colorSpace); FILL_MEMBER(dtiBufferFiller, fColorSpaceSize, &colorSpaceSize); - info.colorSpace()->writeToMemory(reinterpret_cast<void*>(bufferAsInt + colorSpaceOffset)); + info.colorSpace()->writeToMemory(bufferAsCharPtr + colorSpaceOffset); } else { - memset(reinterpret_cast<void*>(bufferAsInt + - offsetof(DeferredTextureImage, fColorSpace)), + memset(bufferAsCharPtr + offsetof(DeferredTextureImage, fColorSpace), 0, sizeof(DeferredTextureImage::fColorSpace)); - memset(reinterpret_cast<void*>(bufferAsInt + - offsetof(DeferredTextureImage, fColorSpaceSize)), + memset(bufferAsCharPtr + offsetof(DeferredTextureImage, fColorSpaceSize), 0, sizeof(DeferredTextureImage::fColorSpaceSize)); } // Fill in the mipmap levels if they exist - uintptr_t mipLevelPtr = pixelsAsInt + SkAlign8(pixmap.getSafeSize()); + char* mipLevelPtr = pixelsAsCharPtr + SkAlign8(pixmap.getSafeSize()); if (useMipMaps) { static_assert(std::is_standard_layout<MipMapLevelData>::value, @@ -625,30 +622,25 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox mipmaps->getLevel(generatedMipLevelIndex, &mipLevel); // Make sure the mipmap data is after the start of the buffer - SkASSERT(mipLevelPtr > bufferAsInt); + SkASSERT(mipLevelPtr > bufferAsCharPtr); // Make sure the mipmap data starts before the end of the buffer - SkASSERT(static_cast<size_t>(mipLevelPtr) < bufferAsInt + pixelOffset + pixelSize); + SkASSERT(mipLevelPtr < bufferAsCharPtr + pixelOffset + pixelSize); // Make sure the mipmap data ends before the end of the buffer SkASSERT(mipLevelPtr + mipLevel.fPixmap.getSafeSize() <= - bufferAsInt + pixelOffset + pixelSize); + bufferAsCharPtr + pixelOffset + pixelSize); // getSafeSize includes rowbyte padding except for the last row, // right? - memcpy(reinterpret_cast<void*>(mipLevelPtr), mipLevel.fPixmap.addr(), - mipLevel.fPixmap.getSafeSize()); + memcpy(mipLevelPtr, mipLevel.fPixmap.addr(), mipLevel.fPixmap.getSafeSize()); - memcpy(reinterpret_cast<void*>(bufferAsInt + - offsetof(DeferredTextureImage, fMipMapLevelData) + - sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) + - offsetof(MipMapLevelData, fPixelData)), - &mipLevelPtr, sizeof(void*)); + memcpy(bufferAsCharPtr + offsetof(DeferredTextureImage, fMipMapLevelData) + + sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) + + offsetof(MipMapLevelData, fPixelData), &mipLevelPtr, sizeof(void*)); size_t rowBytes = mipLevel.fPixmap.rowBytes(); - memcpy(reinterpret_cast<void*>(bufferAsInt + - offsetof(DeferredTextureImage, fMipMapLevelData) + - sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) + - offsetof(MipMapLevelData, fRowBytes)), - &rowBytes, sizeof(rowBytes)); + memcpy(bufferAsCharPtr + offsetof(DeferredTextureImage, fMipMapLevelData) + + sizeof(MipMapLevelData) * (generatedMipLevelIndex + 1) + + offsetof(MipMapLevelData, fRowBytes), &rowBytes, sizeof(rowBytes)); mipLevelPtr += SkAlign8(mipLevel.fPixmap.getSafeSize()); } |