aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/WritePixelsBench.cpp4
-rw-r--r--bench/nanobench.cpp9
-rw-r--r--debugger/QT/SkImageWidget.cpp10
-rw-r--r--experimental/PdfViewer/SkNulCanvas.h4
-rw-r--r--gyp/skia_for_android_framework_defines.gypi1
-rw-r--r--gyp/skia_for_chromium_defines.gypi1
-rw-r--r--include/core/SkBitmap.h24
-rw-r--r--include/core/SkImageInfo.h67
-rw-r--r--samplecode/SampleFatBits.cpp3
-rw-r--r--src/core/SkBitmap.cpp67
-rw-r--r--src/core/SkBitmapDevice.cpp9
-rw-r--r--src/core/SkBitmapProcState.cpp4
-rw-r--r--src/core/SkCanvas.cpp8
-rw-r--r--src/core/SkMallocPixelRef.cpp13
-rw-r--r--src/core/SkPixelRef.cpp16
-rw-r--r--src/effects/gradients/SkGradientShader.cpp7
-rw-r--r--src/gpu/GrSurface.cpp9
-rw-r--r--src/gpu/SkGpuDevice.cpp14
-rw-r--r--src/gpu/SkGrPixelRef.cpp8
-rw-r--r--src/image/SkImage.cpp4
-rw-r--r--src/image/SkImage_Raster.cpp22
-rw-r--r--src/image/SkSurface.cpp5
-rw-r--r--src/image/SkSurface_Raster.cpp8
-rw-r--r--src/images/SkDecodingImageGenerator.cpp14
-rw-r--r--src/lazy/SkCachingPixelRef.cpp4
-rw-r--r--src/utils/debugger/SkDebugCanvas.h4
-rw-r--r--tests/BitmapCopyTest.cpp4
-rw-r--r--tests/BitmapTest.cpp6
-rw-r--r--tests/BlitRowTest.cpp2
-rw-r--r--tests/CachedDecodingPixelRefTest.cpp16
-rw-r--r--tests/CanvasTest.cpp8
-rw-r--r--tests/DrawBitmapRectTest.cpp5
-rw-r--r--tests/PremulAlphaRoundTripTest.cpp5
-rw-r--r--tests/RecordReplaceDrawTest.cpp2
-rw-r--r--tests/SerializationTest.cpp3
-rw-r--r--tests/SurfaceTest.cpp12
-rw-r--r--tools/LazyDecodeBitmap.cpp2
-rw-r--r--tools/sk_tool_utils.cpp4
38 files changed, 185 insertions, 223 deletions
diff --git a/bench/WritePixelsBench.cpp b/bench/WritePixelsBench.cpp
index 5138375ffb..88b2e62ca5 100644
--- a/bench/WritePixelsBench.cpp
+++ b/bench/WritePixelsBench.cpp
@@ -54,9 +54,7 @@ protected:
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 3dcd9db2d9..a484fc2b40 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -133,7 +133,7 @@ static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) {
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 @@ static Target* is_enabled(Benchmark* bench, const Config& config) {
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 03c7e7e0f9..aad979406b 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 2427c4c95b..49d276dfa7 100644
--- a/experimental/PdfViewer/SkNulCanvas.h
+++ b/experimental/PdfViewer/SkNulCanvas.h
@@ -62,8 +62,8 @@ public:
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 507726d149..c5fd7693ba 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 1a3c23fcb2..225eb5b500 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 c58c78d764..4e512c0535 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -78,10 +78,10 @@ public:
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 @@ public:
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 @@ public:
* 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 @@ public:
}
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 3d82dc805c..6204cb3b81 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -136,36 +136,30 @@ bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
* 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 @@ struct SkImageInfo {
}
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 @@ struct SkImageInfo {
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 @@ struct SkImageInfo {
}
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 6057c68fde..c300733131 100644
--- a/samplecode/SampleFatBits.cpp
+++ b/samplecode/SampleFatBits.cpp
@@ -102,8 +102,7 @@ public:
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 928a4b74ed..adb69da1de 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -94,23 +94,22 @@ void SkBitmap::reset() {
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 @@ bool SkBitmap::setInfo(const SkImageInfo& origInfo, size_t rowBytes) {
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 @@ SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) {
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 @@ SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) {
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, size_t rowBytes)
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 @@ bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize,
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 @@ bool SkBitmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
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 @@ bool SkBitmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels,
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 @@ bool SkBitmap::copyTo(SkBitmap* dst, SkColorType dstColorType, Allocator* alloc)
// 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 @@ bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
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 @@ void SkBitmap::validate() const {
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 2287864bae..2711004aef 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -70,11 +70,12 @@ SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkDeviceProperties&
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 @@ bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
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 2fa0294750..068a107153 100644
--- a/src/core/SkBitmapProcState.cpp
+++ b/src/core/SkBitmapProcState.cpp
@@ -273,9 +273,7 @@ bool SkBitmapProcState::possiblyScaleImage() {
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 f071fc99fc..83fe1407d5 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -631,10 +631,8 @@ bool SkCanvas::readPixels(const SkImageInfo& origInfo, void* dstP, size_t rowByt
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 @@ bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size
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 0d50164832..ae29310aea 100644
--- a/src/core/SkMallocPixelRef.cpp
+++ b/src/core/SkMallocPixelRef.cpp
@@ -16,10 +16,9 @@ static void sk_free_releaseproc(void* ptr, void*) {
}
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 @@ SkMallocPixelRef* SkMallocPixelRef::NewAllocate(const SkImageInfo& info,
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 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
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 @@ SkMallocPixelRef::SkMallocPixelRef(const SkImageInfo& info, void* storage,
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 1064070192..1e6db7ec5a 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -81,10 +81,13 @@ void SkPixelRef::setMutex(SkBaseMutex* mutex) {
// 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) : fInfo(info) {
}
-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::notifyPixelsChanged() {
}
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 9d6e856aad..3ac363568c 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -622,11 +622,8 @@ const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() {
}
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 54497fe8c8..52ab4fd11d 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 d26d4f8ed2..1b6558ce43 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -168,17 +168,19 @@ SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
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 2371ea72e3..f56c3b6390 100644
--- a/src/gpu/SkGrPixelRef.cpp
+++ b/src/gpu/SkGrPixelRef.cpp
@@ -116,8 +116,8 @@ SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface,
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 @@ bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
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 a6063846c7..13b6fcd463 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -94,9 +94,9 @@ SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
///////////////////////////////////////////////////////////////////////////////
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 a7e4e009e5..f1d1fcd27f 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -19,16 +19,16 @@ public:
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 @@ public:
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 @@ static void release_data(void* addr, void* context) {
}
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, SkData* data, size_t rowBytes)
}
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 @@ SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
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 @@ SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz
}
// 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 @@ SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro
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 @@ SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro
}
// 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 edc6ef5fa0..9f24e97c50 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -80,10 +80,7 @@ SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) {
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 986994ab8f..167f7733db 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -41,7 +41,7 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
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 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
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 @@ bool SkSurface_Raster::Valid(const SkImageInfo& info, size_t rowBytes) {
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(const SkImageInfo& info, void* pixels, size_t
}
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 5c66c94a53..1d91bcc0f9 100644
--- a/src/images/SkDecodingImageGenerator.cpp
+++ b/src/images/SkDecodingImageGenerator.cpp
@@ -167,8 +167,7 @@ bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info,
}
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 @@ SkImageGenerator* CreateDecodingImageGenerator(
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 bd675324f1..aeaa412508 100644
--- a/src/lazy/SkCachingPixelRef.cpp
+++ b/src/lazy/SkCachingPixelRef.cpp
@@ -44,7 +44,7 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
}
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 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
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 2e9a032e4e..4bb33b7475 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -210,8 +210,8 @@ public:
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 6a20668cf6..3923846226 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -609,8 +609,8 @@ DEF_TEST(BitmapReadPixels, reporter) {
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 4826b831fe..ef69531912 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -51,8 +51,7 @@ static void test_bigwidth(skiatest::Reporter* reporter) {
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 @@ static void test_bigwidth(skiatest::Reporter* reporter) {
// 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 911f2a0f40..4689a305ac 100644
--- a/tests/BlitRowTest.cpp
+++ b/tests/BlitRowTest.cpp
@@ -212,7 +212,7 @@ static void test_diagonal(skiatest::Reporter* reporter) {
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 7c63a0e925..82789a1bfb 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -188,28 +188,26 @@ protected:
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 d4600514b7..216a408155 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -883,17 +883,15 @@ static void test_newraster(skiatest::Reporter* reporter) {
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 720155ca0c..71ad2cf733 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -25,10 +25,7 @@ public:
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 1e655fb738..8bdb77012a 100644
--- a/tests/PremulAlphaRoundTripTest.cpp
+++ b/tests/PremulAlphaRoundTripTest.cpp
@@ -58,9 +58,8 @@ static void fillCanvas(SkCanvas* canvas, SkColorType colorType, PackUnpremulProc
}
}
- 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 6893876402..23bf9adb5a 100644
--- a/tests/RecordReplaceDrawTest.cpp
+++ b/tests/RecordReplaceDrawTest.cpp
@@ -72,7 +72,7 @@ static SkImage* make_image(SkColor color) {
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 450f94f47e..ea03e875a2 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -463,9 +463,8 @@ DEF_TEST(Serialization, reporter) {
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 d317186947..eca929e0cc 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -90,7 +90,7 @@ static SkImage* createImage(ImageType imageType, GrContext* context,
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 @@ static void test_imagepeek(skiatest::Reporter* reporter) {
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 4459cf114a..ec275eacab 100644
--- a/tools/LazyDecodeBitmap.cpp
+++ b/tools/LazyDecodeBitmap.cpp
@@ -39,7 +39,7 @@ bool sk_tools::LazyDecodeBitmap(const void* src,
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 6a2beacac1..02001238e9 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -54,9 +54,7 @@ void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
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);
}