Hide fields in SkImageInfo R=rmistry@google.com TBR=bsalomon Author: reed@google.com Review URL: https://codereview.chromium.org/536003002
diff --git a/bench/WritePixelsBench.cpp b/bench/WritePixelsBench.cpp index 5138375..88b2e62 100644 --- a/bench/WritePixelsBench.cpp +++ b/bench/WritePixelsBench.cpp
@@ -54,9 +54,7 @@ bmp.allocN32Pixels(size.width(), size.height()); canvas->readPixels(&bmp, 0, 0); - SkImageInfo info = bmp.info(); - info.fColorType = fColorType; - info.fAlphaType = fAlphaType; + SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType); for (int loop = 0; loop < loops; ++loop) { canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 3dcd9db..a484fc2 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp
@@ -133,7 +133,7 @@ if (filename.isEmpty()) { return false; } - if (kUnknown_SkColorType == canvas->imageInfo().fColorType) { + if (kUnknown_SkColorType == canvas->imageInfo().colorType()) { return false; } SkBitmap bmp; @@ -357,11 +357,8 @@ return NULL; } - SkImageInfo info; - info.fAlphaType = config.alpha; - info.fColorType = config.color; - info.fWidth = bench->getSize().fX; - info.fHeight = bench->getSize().fY; + SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, + config.color, config.alpha); Target* target = new Target(config);
diff --git a/debugger/QT/SkImageWidget.cpp b/debugger/QT/SkImageWidget.cpp index 03c7e7e..aad9794 100644 --- a/debugger/QT/SkImageWidget.cpp +++ b/debugger/QT/SkImageWidget.cpp
@@ -13,15 +13,11 @@ SkImageWidget::SkImageWidget(SkDebugger *debugger) : QWidget() - , fDebugger(debugger) { + , fDebugger(debugger) +{ this->setStyleSheet("QWidget {background-color: white; border: 1px solid #cccccc;}"); - SkImageInfo info; - info.fWidth = kImageWidgetWidth; - info.fHeight = kImageWidgetHeight; - info.fColorType = kN32_SkColorType; - info.fAlphaType = kPremul_SkAlphaType; - + SkImageInfo info = SkImageInfo::MakeN32Premul(kImageWidgetWidth, kImageWidgetHeight); fSurface = SkSurface::NewRasterDirect(info, fPixels, 4 * kImageWidgetWidth); }
diff --git a/experimental/PdfViewer/SkNulCanvas.h b/experimental/PdfViewer/SkNulCanvas.h index 2427c4c..49d276d 100644 --- a/experimental/PdfViewer/SkNulCanvas.h +++ b/experimental/PdfViewer/SkNulCanvas.h
@@ -62,8 +62,8 @@ virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE { if (NULL != bounds) { bounds->setXYWH(0, 0, - SkIntToScalar(this->imageInfo().fWidth), - SkIntToScalar(this->imageInfo().fHeight)); + SkIntToScalar(this->imageInfo().width()), + SkIntToScalar(this->imageInfo().height())); } return true; }
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi index 507726d..c5fd769 100644 --- a/gyp/skia_for_android_framework_defines.gypi +++ b/gyp/skia_for_android_framework_defines.gypi
@@ -13,6 +13,7 @@ # If these become 'permanent', they should be moved into common_variables.gypi # 'skia_for_android_framework_defines': [ + 'SK_SUPPORT_LEGACY_PUBLIC_IMAGEINFO_FIELDS', 'SK_SUPPORT_LEGACY_ALLOCPIXELS_BOOL', 'SK_SUPPORT_LEGACY_GETDEVICE', # Needed until we fix skbug.com/2440.
diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi index 1a3c23f..225eb5b 100644 --- a/gyp/skia_for_chromium_defines.gypi +++ b/gyp/skia_for_chromium_defines.gypi
@@ -13,6 +13,7 @@ # If these become 'permanent', they should be moved into skia_common.gypi # 'skia_for_chromium_defines': [ + 'SK_SUPPORT_LEGACY_PUBLIC_IMAGEINFO_FIELDS', 'SK_IGNORE_PROPER_FRACTIONAL_SCALING', 'SK_SUPPORT_LEGACY_PICTURE_CLONE', 'SK_IGNORE_ETC1_SUPPORT',
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index c58c78d..4e512c05 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h
@@ -78,10 +78,10 @@ const SkImageInfo& info() const { return fInfo; } - int width() const { return fInfo.fWidth; } - int height() const { return fInfo.fHeight; } - SkColorType colorType() const { return fInfo.fColorType; } - SkAlphaType alphaType() const { return fInfo.fAlphaType; } + int width() const { return fInfo.width(); } + int height() const { return fInfo.height(); } + SkColorType colorType() const { return fInfo.colorType(); } + SkAlphaType alphaType() const { return fInfo.alphaType(); } /** * Return the number of bytes per pixel based on the colortype. If the colortype is @@ -142,7 +142,7 @@ Note this truncates the result to 32bits. Call getSize64() to detect if the real size exceeds 32bits. */ - size_t getSize() const { return fInfo.fHeight * fRowBytes; } + size_t getSize() const { return fInfo.height() * fRowBytes; } /** Return the number of bytes from the pointer returned by getPixels() to the end of the allocated space in the buffer. Required in @@ -154,7 +154,7 @@ * Return the full size of the bitmap, in bytes. */ int64_t computeSize64() const { - return sk_64_mul(fInfo.fHeight, fRowBytes); + return sk_64_mul(fInfo.height(), fRowBytes); } /** @@ -264,18 +264,14 @@ } bool SK_WARN_UNUSED_RESULT tryAllocN32Pixels(int width, int height, bool isOpaque = false) { - SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - if (isOpaque) { - info.fAlphaType = kOpaque_SkAlphaType; - } + SkImageInfo info = SkImageInfo::MakeN32(width, height, + isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); return this->tryAllocPixels(info); } SK_ALLOCPIXELS_RETURN_TYPE allocN32Pixels(int width, int height, bool isOpaque = false) { - SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - if (isOpaque) { - info.fAlphaType = kOpaque_SkAlphaType; - } + SkImageInfo info = SkImageInfo::MakeN32(width, height, + isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); return this->allocPixels(info); }
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 3d82dc8..6204cb3 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h
@@ -136,36 +136,30 @@ * Describe an image's dimensions and pixel type. */ struct SkImageInfo { - int fWidth; - int fHeight; - SkColorType fColorType; - SkAlphaType fAlphaType; +public: + SkImageInfo() + : fWidth(0) + , fHeight(0) + , fColorType(kUnknown_SkColorType) + , fAlphaType(kIgnore_SkAlphaType) + {} static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) { - SkImageInfo info = { - width, height, ct, at - }; - return info; + return SkImageInfo(width, height, ct, at); } /** * Sets colortype to the native ARGB32 type. */ static SkImageInfo MakeN32(int width, int height, SkAlphaType at) { - SkImageInfo info = { - width, height, kN32_SkColorType, at - }; - return info; + return SkImageInfo(width, height, kN32_SkColorType, at); } /** * Sets colortype to the native ARGB32 type, and the alphatype to premul. */ static SkImageInfo MakeN32Premul(int width, int height) { - SkImageInfo info = { - width, height, kN32_SkColorType, kPremul_SkAlphaType - }; - return info; + return SkImageInfo(width, height, kN32_SkColorType, kPremul_SkAlphaType); } /** @@ -176,24 +170,15 @@ } static SkImageInfo MakeA8(int width, int height) { - SkImageInfo info = { - width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType - }; - return info; + return SkImageInfo(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType); } static SkImageInfo MakeUnknown(int width, int height) { - SkImageInfo info = { - width, height, kUnknown_SkColorType, kIgnore_SkAlphaType - }; - return info; + return SkImageInfo(width, height, kUnknown_SkColorType, kIgnore_SkAlphaType); } static SkImageInfo MakeUnknown() { - SkImageInfo info = { - 0, 0, kUnknown_SkColorType, kIgnore_SkAlphaType - }; - return info; + return SkImageInfo(); } int width() const { return fWidth; } @@ -217,6 +202,14 @@ return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType); } + SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { + return SkImageInfo::Make(fWidth, fHeight, fColorType, newAlphaType); + } + + SkImageInfo makeColorType(SkColorType newColorType) const { + return SkImageInfo::Make(fWidth, fHeight, newColorType, fAlphaType); + } + int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } @@ -256,6 +249,24 @@ } SkDEBUGCODE(void validate() const;) + +#ifdef SK_SUPPORT_LEGACY_PUBLIC_IMAGEINFO_FIELDS +public: +#else +private: +#endif + int fWidth; + int fHeight; + SkColorType fColorType; + SkAlphaType fAlphaType; + +private: + SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at) + : fWidth(width) + , fHeight(height) + , fColorType(ct) + , fAlphaType(at) + {} }; #endif
diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp index 6057c68..c300733 100644 --- a/samplecode/SampleFatBits.cpp +++ b/samplecode/SampleFatBits.cpp
@@ -102,8 +102,7 @@ SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); fMinSurface.reset(SkSurface::NewRaster(info)); - info.fWidth *= zoom; - info.fHeight *= zoom; + info = info.makeWH(width * zoom, height * zoom); fMaxSurface.reset(SkSurface::NewRaster(info)); }
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 928a4b7..adb69da 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp
@@ -94,23 +94,22 @@ void SkBitmap::getBounds(SkRect* bounds) const { SkASSERT(bounds); bounds->set(0, 0, - SkIntToScalar(fInfo.fWidth), SkIntToScalar(fInfo.fHeight)); + SkIntToScalar(fInfo.width()), SkIntToScalar(fInfo.height())); } void SkBitmap::getBounds(SkIRect* bounds) const { SkASSERT(bounds); - bounds->set(0, 0, fInfo.fWidth, fInfo.fHeight); + bounds->set(0, 0, fInfo.width(), fInfo.height()); } /////////////////////////////////////////////////////////////////////////////// -bool SkBitmap::setInfo(const SkImageInfo& origInfo, size_t rowBytes) { - SkImageInfo info = origInfo; - - if (!SkColorTypeValidateAlphaType(info.fColorType, info.fAlphaType, - &info.fAlphaType)) { +bool SkBitmap::setInfo(const SkImageInfo& info, size_t rowBytes) { + SkAlphaType newAT = info.alphaType(); + if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAT)) { return reset_return_false(this); } + // don't look at info.alphaType(), since newAT is the real value... // require that rowBytes fit in 31bits int64_t mrb = info.minRowBytes64(); @@ -135,19 +134,19 @@ this->freePixels(); - fInfo = info; + fInfo = info.makeAlphaType(newAT); fRowBytes = SkToU32(rowBytes); return true; } -bool SkBitmap::setAlphaType(SkAlphaType alphaType) { - if (!SkColorTypeValidateAlphaType(fInfo.fColorType, alphaType, &alphaType)) { +bool SkBitmap::setAlphaType(SkAlphaType newAlphaType) { + if (!SkColorTypeValidateAlphaType(fInfo.colorType(), newAlphaType, &newAlphaType)) { return false; } - if (fInfo.fAlphaType != alphaType) { - fInfo.fAlphaType = alphaType; + if (fInfo.alphaType() != newAlphaType) { + fInfo = fInfo.makeAlphaType(newAlphaType); if (fPixelRef) { - fPixelRef->changeAlphaType(alphaType); + fPixelRef->changeAlphaType(newAlphaType); } } return true; @@ -179,21 +178,21 @@ if (pr) { if (kUnknown_SkColorType != fInfo.colorType()) { const SkImageInfo& prInfo = pr->info(); - SkASSERT(fInfo.fWidth <= prInfo.fWidth); - SkASSERT(fInfo.fHeight <= prInfo.fHeight); - SkASSERT(fInfo.fColorType == prInfo.fColorType); - switch (prInfo.fAlphaType) { + SkASSERT(fInfo.width() <= prInfo.width()); + SkASSERT(fInfo.height() <= prInfo.height()); + SkASSERT(fInfo.colorType() == prInfo.colorType()); + switch (prInfo.alphaType()) { case kIgnore_SkAlphaType: - SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); + SkASSERT(fInfo.alphaType() == kIgnore_SkAlphaType); break; case kOpaque_SkAlphaType: case kPremul_SkAlphaType: - SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType || - fInfo.fAlphaType == kPremul_SkAlphaType); + SkASSERT(fInfo.alphaType() == kOpaque_SkAlphaType || + fInfo.alphaType() == kPremul_SkAlphaType); break; case kUnpremul_SkAlphaType: - SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType || - fInfo.fAlphaType == kUnpremul_SkAlphaType); + SkASSERT(fInfo.alphaType() == kOpaque_SkAlphaType || + fInfo.alphaType() == kUnpremul_SkAlphaType); break; } } @@ -202,8 +201,7 @@ if (pr) { const SkImageInfo& info = pr->info(); - fPixelRefOrigin.set(SkPin32(dx, 0, info.fWidth), - SkPin32(dy, 0, info.fHeight)); + fPixelRefOrigin.set(SkPin32(dx, 0, info.width()), SkPin32(dy, 0, info.height())); } else { // ignore dx,dy if there is no pixelref fPixelRefOrigin.setZero(); @@ -310,7 +308,7 @@ bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactory* factory, SkColorTable* ctable) { - if (kIndex_8_SkColorType == requestedInfo.fColorType && NULL == ctable) { + if (kIndex_8_SkColorType == requestedInfo.colorType() && NULL == ctable) { return reset_return_false(this); } if (!this->setInfo(requestedInfo)) { @@ -467,8 +465,7 @@ SkAutoLockPixels lock(*this); const uint8_t* srcP = reinterpret_cast<const uint8_t*>(getPixels()); uint8_t* dstP = reinterpret_cast<uint8_t*>(dst); - for (int row = 0; row < fInfo.fHeight; - row++, srcP += fRowBytes, dstP += dstRowBytes) { + for (int row = 0; row < fInfo.height(); row++, srcP += fRowBytes, dstP += dstRowBytes) { memcpy(dstP, srcP, rowBytes); } @@ -857,10 +854,8 @@ return false; } - SkImageInfo dstInfo = requestedDstInfo; // the intersect may have shrunk info's logical size - dstInfo.fWidth = srcR.width(); - dstInfo.fHeight = srcR.height(); + const SkImageInfo dstInfo = requestedDstInfo.makeWH(srcR.width(), srcR.height()); // if x or y are negative, then we have to adjust pixels if (x > 0) { @@ -881,9 +876,7 @@ return false; } - SkImageInfo srcInfo = this->info(); - srcInfo.fWidth = dstInfo.width(); - srcInfo.fHeight = dstInfo.height(); + const SkImageInfo srcInfo = this->info().makeWH(dstInfo.width(), dstInfo.height()); const void* srcPixels = this->getAddr(srcR.x(), srcR.y()); return SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, this->rowBytes(), @@ -936,8 +929,7 @@ // The only way to be readyToDraw is if fPixelRef is non NULL. SkASSERT(fPixelRef != NULL); - SkImageInfo dstInfo = src->info(); - dstInfo.fColorType = dstColorType; + const SkImageInfo dstInfo = src->info().makeColorType(dstColorType); SkBitmap tmpDst; if (!tmpDst.setInfo(dstInfo)) { @@ -1009,8 +1001,7 @@ rowBytes = 0; } - SkImageInfo info = fInfo; - info.fColorType = dstCT; + const SkImageInfo info = fInfo.makeColorType(dstCT); if (!dst->setInfo(info, rowBytes)) { return false; } @@ -1338,7 +1329,7 @@ SkASSERT(fPixelRefOrigin.fX >= 0); SkASSERT(fPixelRefOrigin.fY >= 0); SkASSERT(fPixelRef->info().width() >= (int)this->width() + fPixelRefOrigin.fX); - SkASSERT(fPixelRef->info().fHeight >= (int)this->height() + fPixelRefOrigin.fY); + SkASSERT(fPixelRef->info().height() >= (int)this->height() + fPixelRefOrigin.fY); SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes()); } else { SkASSERT(NULL == fColorTable);
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index 2287864b..2711004 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp
@@ -70,11 +70,12 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, const SkDeviceProperties* props) { - SkImageInfo info = origInfo; - if (!valid_for_bitmap_device(info, &info.fAlphaType)) { + SkAlphaType newAT = origInfo.alphaType(); + if (!valid_for_bitmap_device(origInfo, &newAT)) { return NULL; } + const SkImageInfo info = origInfo.makeAlphaType(newAT); SkBitmap bitmap; if (kUnknown_SkColorType == info.colorType()) { @@ -150,9 +151,7 @@ return false; } - SkImageInfo dstInfo = fBitmap.info(); - dstInfo.fWidth = srcInfo.width(); - dstInfo.fHeight = srcInfo.height(); + const SkImageInfo dstInfo = fBitmap.info().makeWH(srcInfo.width(), srcInfo.height()); void* dstPixels = fBitmap.getAddr(x, y); size_t dstRowBytes = fBitmap.rowBytes();
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index 2fa0294..068a107 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp
@@ -273,9 +273,7 @@ SkScalar invScaleFixup = level.fScale; fInvMatrix.postScale(invScaleFixup, invScaleFixup); - SkImageInfo info = fOrigBitmap.info(); - info.fWidth = level.fWidth; - info.fHeight = level.fHeight; + const SkImageInfo info = fOrigBitmap.info().makeWH(level.fWidth, level.fHeight); // todo: if we could wrap the fCurrMip in a pixelref, then we could just install // that here, and not need to explicitly track it ourselves. fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes);
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index f071fc9..83fe140 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp
@@ -631,10 +631,8 @@ return false; } - SkImageInfo info = origInfo; // the intersect may have shrunk info's logical size - info.fWidth = srcR.width(); - info.fHeight = srcR.height(); + const SkImageInfo info = origInfo.makeWH(srcR.width(), srcR.height()); // if x or y are negative, then we have to adjust pixels if (x > 0) { @@ -686,10 +684,8 @@ return false; } - SkImageInfo info = origInfo; // the intersect may have shrunk info's logical size - info.fWidth = target.width(); - info.fHeight = target.height(); + const SkImageInfo info = origInfo.makeWH(target.width(), target.height()); // if x or y are negative, then we have to adjust pixels if (x > 0) {
diff --git a/src/core/SkMallocPixelRef.cpp b/src/core/SkMallocPixelRef.cpp index 0d50164..ae29310 100644 --- a/src/core/SkMallocPixelRef.cpp +++ b/src/core/SkMallocPixelRef.cpp
@@ -16,10 +16,9 @@ } static bool is_valid(const SkImageInfo& info, SkColorTable* ctable) { - if (info.fWidth < 0 || - info.fHeight < 0 || - (unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType || - (unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) + if (info.width() < 0 || info.height() < 0 || + (unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType || + (unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) { return false; } @@ -72,7 +71,7 @@ rowBytes = minRB; } - int64_t bigSize = (int64_t)info.fHeight * rowBytes; + int64_t bigSize = (int64_t)info.height() * rowBytes; if (!sk_64_isS32(bigSize)) { return NULL; } @@ -142,7 +141,7 @@ SkASSERT(is_valid(info, ctable)); SkASSERT(rowBytes >= info.minRowBytes()); - if (kIndex_8_SkColorType != info.fColorType) { + if (kIndex_8_SkColorType != info.colorType()) { ctable = NULL; } @@ -165,7 +164,7 @@ SkASSERT(is_valid(info, ctable)); SkASSERT(rowBytes >= info.minRowBytes()); - if (kIndex_8_SkColorType != info.fColorType) { + if (kIndex_8_SkColorType != info.colorType()) { ctable = NULL; }
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 1064070..1e6db7e 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp
@@ -81,10 +81,13 @@ // just need a > 0 value, so pick a funny one to aid in debugging #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 -SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(info) { - SkAssertResult(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaType(), - const_cast<SkAlphaType*>(&fInfo.fAlphaType))); +static SkImageInfo validate_info(const SkImageInfo& info) { + SkAlphaType newAlphaType = info.alphaType(); + SkAssertResult(SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAlphaType)); + return info.makeAlphaType(newAlphaType); +} +SkPixelRef::SkPixelRef(const SkImageInfo& info) : fInfo(validate_info(info)) { this->setMutex(NULL); fRec.zero(); fLockCount = 0; @@ -94,10 +97,7 @@ } -SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(info) { - SkAssertResult(SkColorTypeValidateAlphaType(fInfo.colorType(), fInfo.alphaType(), - const_cast<SkAlphaType*>(&fInfo.fAlphaType))); - +SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) : fInfo(validate_info(info)) { this->setMutex(mutex); fRec.zero(); fLockCount = 0; @@ -234,7 +234,7 @@ } void SkPixelRef::changeAlphaType(SkAlphaType at) { - *const_cast<SkAlphaType*>(&fInfo.fAlphaType) = at; + *const_cast<SkImageInfo*>(&fInfo) = fInfo.makeAlphaType(at); } void SkPixelRef::setImmutable() {
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 9d6e856..3ac3635 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp
@@ -622,11 +622,8 @@ } void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache* cache) { - SkImageInfo info; - info.fWidth = kCache32Count; - info.fHeight = 4; // for our 4 dither rows - info.fAlphaType = kPremul_SkAlphaType; - info.fColorType = kN32_SkColorType; + const int kNumberOfDitherRows = 4; + const SkImageInfo info = SkImageInfo::MakeN32Premul(kCache32Count, kNumberOfDitherRows); SkASSERT(NULL == cache->fCache32PixelRef); cache->fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, NULL);
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index 54497fe..52ab4fd 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp
@@ -13,14 +13,11 @@ #include <stdio.h> SkImageInfo GrSurface::info() const { - SkImageInfo info; - if (!GrPixelConfig2ColorType(this->config(), &info.fColorType)) { + SkColorType colorType; + if (!GrPixelConfig2ColorType(this->config(), &colorType)) { sk_throw(); } - info.fWidth = this->width(); - info.fHeight = this->height(); - info.fAlphaType = kPremul_SkAlphaType; - return info; + return SkImageInfo::Make(this->width(), this->height(), colorType, kPremul_SkAlphaType); } bool GrSurface::savePixels(const char* filename) {
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index d26d4f8..1b6558c 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp
@@ -168,17 +168,19 @@ return NULL; } - SkImageInfo info = origInfo; + SkColorType ct = origInfo.colorType(); + SkAlphaType at = origInfo.alphaType(); // TODO: perhas we can loosen this check now that colortype is more detailed // e.g. can we support both RGBA and BGRA here? - if (kRGB_565_SkColorType == info.colorType()) { - info.fAlphaType = kOpaque_SkAlphaType; // force this setting + if (kRGB_565_SkColorType == ct) { + at = kOpaque_SkAlphaType; // force this setting } else { - info.fColorType = kN32_SkColorType; - if (kOpaque_SkAlphaType != info.alphaType()) { - info.fAlphaType = kPremul_SkAlphaType; // force this setting + ct = kN32_SkColorType; + if (kOpaque_SkAlphaType != at) { + at = kPremul_SkAlphaType; // force this setting } } + const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height(), ct, at); GrTextureDesc desc; desc.fFlags = kRenderTarget_GrTextureFlagBit;
diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp index 2371ea7..f56c3b6 100644 --- a/src/gpu/SkGrPixelRef.cpp +++ b/src/gpu/SkGrPixelRef.cpp
@@ -116,8 +116,8 @@ fUnlock = transferCacheLock; if (fSurface) { - SkASSERT(info.fWidth <= fSurface->width()); - SkASSERT(info.fHeight <= fSurface->height()); + SkASSERT(info.width() <= fSurface->width()); + SkASSERT(info.height() <= fSurface->height()); } } @@ -166,9 +166,9 @@ height = subset->height(); } else { left = 0; - width = this->info().fWidth; + width = this->info().width(); top = 0; - height = this->info().fHeight; + height = this->info().height(); } if (!dst->tryAllocN32Pixels(width, height)) { SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\n");
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index a606384..13b6fcd 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp
@@ -94,9 +94,9 @@ /////////////////////////////////////////////////////////////////////////////// static bool raster_canvas_supports(const SkImageInfo& info) { - switch (info.fColorType) { + switch (info.colorType()) { case kN32_SkColorType: - return kUnpremul_SkAlphaType != info.fAlphaType; + return kUnpremul_SkAlphaType != info.alphaType(); case kRGB_565_SkColorType: return true; case kAlpha_8_SkColorType:
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index a7e4e00..f1d1fcd 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp
@@ -19,16 +19,16 @@ const int maxDimension = SK_MaxS32 >> 2; const size_t kMaxPixelByteSize = SK_MaxS32; - if (info.fWidth < 0 || info.fHeight < 0) { + if (info.width() < 0 || info.height() < 0) { return false; } - if (info.fWidth > maxDimension || info.fHeight > maxDimension) { + if (info.width() > maxDimension || info.height() > maxDimension) { return false; } - if ((unsigned)info.fColorType > (unsigned)kLastEnum_SkColorType) { + if ((unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType) { return false; } - if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) { + if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) { return false; } @@ -42,7 +42,7 @@ return false; } - int64_t size = (int64_t)info.fHeight * rowBytes; + int64_t size = (int64_t)info.height() * rowBytes; if (size > (int64_t)kMaxPixelByteSize) { return false; } @@ -102,7 +102,7 @@ } SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) - : INHERITED(info.fWidth, info.fHeight) + : INHERITED(info.width(), info.height()) { data->ref(); void* addr = const_cast<void*>(data->data()); @@ -114,7 +114,7 @@ } SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes) - : INHERITED(info.fWidth, info.fHeight) + : INHERITED(info.width(), info.height()) { fBitmap.setInfo(info, rowBytes); fBitmap.setPixelRef(pr); @@ -170,7 +170,7 @@ if (!SkImage_Raster::ValidArgs(info, rowBytes)) { return NULL; } - if (0 == info.fWidth && 0 == info.fHeight) { + if (0 == info.width() && 0 == info.height()) { return SkImage_Raster::NewEmpty(); } // check this after empty-check @@ -179,7 +179,7 @@ } // Here we actually make a copy of the caller's pixel data - SkAutoDataUnref data(SkData::NewWithCopy(pixels, info.fHeight * rowBytes)); + SkAutoDataUnref data(SkData::NewWithCopy(pixels, info.height() * rowBytes)); return SkNEW_ARGS(SkImage_Raster, (info, data, rowBytes)); } @@ -188,7 +188,7 @@ if (!SkImage_Raster::ValidArgs(info, rowBytes)) { return NULL; } - if (0 == info.fWidth && 0 == info.fHeight) { + if (0 == info.width() && 0 == info.height()) { return SkImage_Raster::NewEmpty(); } // check this after empty-check @@ -197,7 +197,7 @@ } // did they give us enough data? - size_t size = info.fHeight * rowBytes; + size_t size = info.height() * rowBytes; if (data->size() < size) { return NULL; }
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index edc6ef5..9f24e97 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp
@@ -80,10 +80,7 @@ fGenerationID = 0; } -SkSurface::SkSurface(const SkImageInfo& info) - : fWidth(info.fWidth) - , fHeight(info.fHeight) -{ +SkSurface::SkSurface(const SkImageInfo& info) : fWidth(info.width()), fHeight(info.height()) { SkASSERT(fWidth >= 0); SkASSERT(fHeight >= 0); fGenerationID = 0;
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index 986994a..167f773 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp
@@ -41,7 +41,7 @@ static const size_t kMaxTotalSize = SK_MaxS32; int shift = 0; - switch (info.fColorType) { + switch (info.colorType()) { case kAlpha_8_SkColorType: shift = 0; break; @@ -59,7 +59,7 @@ return true; } - uint64_t minRB = (uint64_t)info.fWidth << shift; + uint64_t minRB = (uint64_t)info.width() << shift; if (minRB > rowBytes) { return false; } @@ -69,7 +69,7 @@ return false; } - uint64_t size = sk_64_mul(info.fHeight, rowBytes); + uint64_t size = sk_64_mul(info.height(), rowBytes); if (size > kMaxTotalSize) { return false; } @@ -86,7 +86,7 @@ } SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr) - : INHERITED(pr->info().fWidth, pr->info().fHeight) + : INHERITED(pr->info().width(), pr->info().height()) { const SkImageInfo& info = pr->info();
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp index 5c66c94..1d91bcc 100644 --- a/src/images/SkDecodingImageGenerator.cpp +++ b/src/images/SkDecodingImageGenerator.cpp
@@ -167,8 +167,7 @@ } decoder->setDitherImage(fDitherImage); decoder->setSampleSize(fSampleSize); - decoder->setRequireUnpremultipliedColors( - info.fAlphaType == kUnpremul_SkAlphaType); + decoder->setRequireUnpremultipliedColors(info.alphaType() == kUnpremul_SkAlphaType); SkBitmap bitmap; TargetAllocator allocator(fInfo, pixels, rowBytes); @@ -240,19 +239,20 @@ SkASSERT(bitmap.colorType() != opts.fRequestedColorType); return NULL; // Can not translate to needed config. } - info.fColorType = opts.fRequestedColorType; + info = info.makeColorType(opts.fRequestedColorType); } - if (opts.fRequireUnpremul && info.fAlphaType != kOpaque_SkAlphaType) { - info.fAlphaType = kUnpremul_SkAlphaType; + if (opts.fRequireUnpremul && info.alphaType() != kOpaque_SkAlphaType) { + info = info.makeAlphaType(kUnpremul_SkAlphaType); } - if (!SkColorTypeValidateAlphaType(info.fColorType, info.fAlphaType, &info.fAlphaType)) { + SkAlphaType newAlphaType = info.alphaType(); + if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &newAlphaType)) { return NULL; } return SkNEW_ARGS(DecodingImageGenerator, - (data, autoStream.detach(), info, + (data, autoStream.detach(), info.makeAlphaType(newAlphaType), opts.fSampleSize, opts.fDitherImage)); }
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp index bd67532..aeaa412 100644 --- a/src/lazy/SkCachingPixelRef.cpp +++ b/src/lazy/SkCachingPixelRef.cpp
@@ -44,7 +44,7 @@ } const SkImageInfo& info = this->info(); - if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight, &fLockedBitmap)) { + if (!SkBitmapCache::Find(this->getGenerationID(), info.width(), info.height(), &fLockedBitmap)) { // Cache has been purged, must re-decode. if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { fErrorInDecoding = true; @@ -55,7 +55,7 @@ return false; } fLockedBitmap.setImmutable(); - SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, fLockedBitmap); + SkBitmapCache::Add(this->getGenerationID(), info.width(), info.height(), fLockedBitmap); } // Now bitmap should contain a concrete PixelRef of the decoded image.
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h index 2e9a032..4bb33b7 100644 --- a/src/utils/debugger/SkDebugCanvas.h +++ b/src/utils/debugger/SkDebugCanvas.h
@@ -210,8 +210,8 @@ virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE { if (NULL != bounds) { bounds->setXYWH(0, 0, - SkIntToScalar(this->imageInfo().fWidth), - SkIntToScalar(this->imageInfo().fHeight)); + SkIntToScalar(this->imageInfo().width()), + SkIntToScalar(this->imageInfo().height())); } return true; }
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 6a20668..3923846 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp
@@ -609,8 +609,8 @@ for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { clear_4x4_pixels(dstPixels); - dstInfo.fWidth = gRec[i].fRequestedDstSize.width(); - dstInfo.fHeight = gRec[i].fRequestedDstSize.height(); + dstInfo = dstInfo.makeWH(gRec[i].fRequestedDstSize.width(), + gRec[i].fRequestedDstSize.height()); bool success = srcBM.readPixels(dstInfo, dstPixels, rowBytes, gRec[i].fRequestedSrcLoc.x(), gRec[i].fRequestedSrcLoc.y());
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp index 4826b83..ef69531 100644 --- a/tests/BitmapTest.cpp +++ b/tests/BitmapTest.cpp
@@ -51,8 +51,7 @@ SkImageInfo info = SkImageInfo::MakeA8(width, 1); REPORTER_ASSERT(reporter, bm.setInfo(info)); - info.fColorType = kRGB_565_SkColorType; - REPORTER_ASSERT(reporter, bm.setInfo(info)); + REPORTER_ASSERT(reporter, bm.setInfo(info.makeColorType(kRGB_565_SkColorType))); // for a 4-byte config, this width will compute a rowbytes of 0x80000000, // which does not fit in a int32_t. setConfig should detect this, and fail. @@ -60,8 +59,7 @@ // TODO: perhaps skia can relax this, and only require that rowBytes fit // in a uint32_t (or larger), but for now this is the constraint. - info.fColorType = kN32_SkColorType; - REPORTER_ASSERT(reporter, !bm.setInfo(info)); + REPORTER_ASSERT(reporter, !bm.setInfo(info.makeColorType(kN32_SkColorType))); } /**
diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp index 911f2a0..4689a30 100644 --- a/tests/BlitRowTest.cpp +++ b/tests/BlitRowTest.cpp
@@ -212,7 +212,7 @@ kPremul_SkAlphaType); for (size_t i = 0; i < SK_ARRAY_COUNT(gDstColorType); i++) { - info.fColorType = gDstColorType[i]; + info = info.makeColorType(gDstColorType[i]); SkBitmap dstBM0, dstBM1; dstBM0.allocPixels(info);
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp index 7c63a0e..82789a1 100644 --- a/tests/CachedDecodingPixelRefTest.cpp +++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -188,28 +188,26 @@ if ((NULL == info) || (kFailGetInfo_TestType == fType)) { return false; } - info->fWidth = TestImageGenerator::Width(); - info->fHeight = TestImageGenerator::Height(); - info->fColorType = kN32_SkColorType; - info->fAlphaType = kOpaque_SkAlphaType; + *info = SkImageInfo::MakeN32(TestImageGenerator::Width(), + TestImageGenerator::Height(), + kOpaque_SkAlphaType); return true; } virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) SK_OVERRIDE { REPORTER_ASSERT(fReporter, pixels != NULL); - size_t minRowBytes - = static_cast<size_t>(info.fWidth * info.bytesPerPixel()); + size_t minRowBytes = static_cast<size_t>(info.width() * info.bytesPerPixel()); REPORTER_ASSERT(fReporter, rowBytes >= minRowBytes); if ((NULL == pixels) || (fType != kSucceedGetPixels_TestType) - || (info.fColorType != kN32_SkColorType)) { + || (info.colorType() != kN32_SkColorType)) { return false; } char* bytePtr = static_cast<char*>(pixels); - for (int y = 0; y < info.fHeight; ++y) { + for (int y = 0; y < info.height(); ++y) { sk_memset32(reinterpret_cast<SkColor*>(bytePtr), - TestImageGenerator::Color(), info.fWidth); + TestImageGenerator::Color(), info.width()); bytePtr += rowBytes; } return true;
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index d460051..216a408 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp
@@ -883,17 +883,15 @@ SkDELETE(canvas); // now try a deliberately bad info - info.fWidth = -1; + info = info.makeWH(-1, info.height()); REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); // too big - info.fWidth = 1 << 30; - info.fHeight = 1 << 30; + info = info.makeWH(1 << 30, 1 << 30); REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); // not a valid pixel type - info.fWidth = info.fHeight = 10; - info.fColorType = kUnknown_SkColorType; + info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info)); // We should succeed with a zero-sized valid info
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp index 720155c..71ad2cf 100644 --- a/tests/DrawBitmapRectTest.cpp +++ b/tests/DrawBitmapRectTest.cpp
@@ -25,10 +25,7 @@ protected: virtual bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { - info->fWidth = 100; - info->fHeight = 100; - info->fColorType = kN32_SkColorType; - info->fAlphaType = kPremul_SkAlphaType; + *info = SkImageInfo::MakeN32Premul(100, 100); return true; } // default onGetPixels() returns false, which is what we want.
diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp index 1e655fb..8bdb770 100644 --- a/tests/PremulAlphaRoundTripTest.cpp +++ b/tests/PremulAlphaRoundTripTest.cpp
@@ -58,9 +58,8 @@ } } - SkImageInfo info = bmp.info(); - info.fColorType = colorType; - info.fAlphaType = kUnpremul_SkAlphaType; + const SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), + colorType, kUnpremul_SkAlphaType); canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); }
diff --git a/tests/RecordReplaceDrawTest.cpp b/tests/RecordReplaceDrawTest.cpp index 6893876..23bf9ad 100644 --- a/tests/RecordReplaceDrawTest.cpp +++ b/tests/RecordReplaceDrawTest.cpp
@@ -72,7 +72,7 @@ const SkPMColor pmcolor = SkPreMultiplyColor(color); const SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); const size_t rowBytes = info.minRowBytes(); - const size_t size = rowBytes * info.fHeight; + const size_t size = rowBytes * info.height(); SkAutoMalloc addr(size); sk_memset32((SkPMColor*)addr.get(), pmcolor, SkToInt(size >> 2));
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 450f94f..ea03e87 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp
@@ -463,9 +463,8 @@ validBitmap.setInfo(info); // Create a bitmap with a really large height - info.fHeight = 1000000000; SkBitmap invalidBitmap; - invalidBitmap.setInfo(info); + invalidBitmap.setInfo(info.makeWH(info.width(), 1000000000)); // The deserialization should succeed, and the rendering shouldn't crash, // even when the device fails to initialize, due to its size
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index d317186..eca929e 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp
@@ -90,7 +90,7 @@ const SkPMColor pmcolor = SkPreMultiplyColor(color); const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); const size_t rowBytes = info.minRowBytes(); - const size_t size = rowBytes * info.fHeight; + const size_t size = rowBytes * info.height(); void* addr = sk_malloc_throw(size); sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); @@ -142,11 +142,11 @@ bool success = (NULL != addr); REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); if (success) { - REPORTER_ASSERT(reporter, 10 == info.fWidth); - REPORTER_ASSERT(reporter, 10 == info.fHeight); - REPORTER_ASSERT(reporter, kN32_SkColorType == info.fColorType); - REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.fAlphaType || - kOpaque_SkAlphaType == info.fAlphaType); + REPORTER_ASSERT(reporter, 10 == info.width()); + REPORTER_ASSERT(reporter, 10 == info.height()); + REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); + REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || + kOpaque_SkAlphaType == info.alphaType()); REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); }
diff --git a/tools/LazyDecodeBitmap.cpp b/tools/LazyDecodeBitmap.cpp index 4459cf1..ec275ea 100644 --- a/tools/LazyDecodeBitmap.cpp +++ b/tools/LazyDecodeBitmap.cpp
@@ -39,7 +39,7 @@ return false; } SkDiscardableMemory::Factory* pool = NULL; - if ((!FLAGS_useVolatileCache) || (info.fWidth * info.fHeight < 32 * 1024)) { + if ((!FLAGS_useVolatileCache) || (info.width() * info.height() < 32 * 1024)) { // how to do switching with SkDiscardableMemory. pool = SkGetGlobalDiscardableMemoryPool(); // Only meaningful if platform has a default discardable
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 6a2beac..0200123 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp
@@ -54,9 +54,7 @@ SkBitmap tmp(bitmap); tmp.lockPixels(); - SkImageInfo info = tmp.info(); - info.fColorType = colorType; - info.fAlphaType = alphaType; + const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorType, alphaType); canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); }