aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-15 02:38:22 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-15 02:38:22 +0000
commit32678d9a453e2c9fd26e92be429cdd84250b4d85 (patch)
tree030829a85feda7e6488b7d46f8ad87a0e2fdf443
parent78f6ddc1a0a1b1833c71f636e89e796505688b01 (diff)
use some helper Make functions to initialize SkImageInfo
BUG= R=halcanary@google.com, scroggo@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/137993012 git-svn-id: http://skia.googlecode.com/svn/trunk@13081 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gm/image.cpp4
-rw-r--r--gm/srcmode.cpp7
-rw-r--r--include/core/SkImageInfo.h50
-rw-r--r--platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp4
-rw-r--r--samplecode/SampleFatBits.cpp4
-rw-r--r--src/core/SkImageFilterUtils.cpp7
-rw-r--r--src/core/SkScaledImageCache.cpp9
-rw-r--r--tests/MallocPixelRefTest.cpp2
-rw-r--r--tests/PixelRefTest.cpp2
9 files changed, 59 insertions, 30 deletions
diff --git a/gm/image.cpp b/gm/image.cpp
index 93e16b718c..f5f5228c61 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -178,9 +178,7 @@ protected:
// since we draw into this directly, we need to start fresh
sk_bzero(fBuffer, fBufferSize);
- SkImageInfo info = {
- W, H, kPMColor_SkColorType, kPremul_SkAlphaType
- };
+ SkImageInfo info = SkImageInfo::MakeN32Premul(W, H);
SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB));
SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info));
SkAutoTUnref<SkSurface> surf2(SkSurface::NewPicture(info.fWidth, info.fHeight));
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp
index 666a36bb04..6aa236f3f4 100644
--- a/gm/srcmode.cpp
+++ b/gm/srcmode.cpp
@@ -117,12 +117,7 @@ protected:
static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size,
bool skipGPU) {
- SkImageInfo info = {
- size.width(),
- size.height(),
- kPMColor_SkColorType,
- kPremul_SkAlphaType
- };
+ SkImageInfo info = SkImageInfo::MakeN32Premul(size);
#if SK_SUPPORT_GPU
SkBaseDevice* dev = canvas->getDevice();
if (!skipGPU && dev->accessRenderTarget()) {
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 1165479f74..e37f2ef6d9 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -9,6 +9,7 @@
#define SkImageInfo_DEFINED
#include "SkTypes.h"
+#include "SkSize.h"
class SkFlattenableWriteBuffer;
class SkFlattenableReadBuffer;
@@ -109,6 +110,55 @@ struct SkImageInfo {
SkColorType fColorType;
SkAlphaType fAlphaType;
+ static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) {
+ SkASSERT(width >= 0);
+ SkASSERT(height >= 0);
+ SkImageInfo info = {
+ width, height, ct, at
+ };
+ return info;
+ }
+
+ /**
+ * Sets colortype to the native ARGB32 type.
+ */
+ static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
+ SkASSERT(width >= 0);
+ SkASSERT(height >= 0);
+ SkImageInfo info = {
+ width, height, kPMColor_SkColorType, at
+ };
+ return info;
+ }
+
+ /**
+ * Sets colortype to the native ARGB32 type, and the alphatype to premul.
+ */
+ static SkImageInfo MakeN32Premul(int width, int height) {
+ SkASSERT(width >= 0);
+ SkASSERT(height >= 0);
+ SkImageInfo info = {
+ width, height, kPMColor_SkColorType, kPremul_SkAlphaType
+ };
+ return info;
+ }
+
+ /**
+ * Sets colortype to the native ARGB32 type, and the alphatype to premul.
+ */
+ static SkImageInfo MakeN32Premul(const SkISize& size) {
+ return MakeN32Premul(size.width(), size.height());
+ }
+
+ static SkImageInfo MakeA8(int width, int height) {
+ SkASSERT(width >= 0);
+ SkASSERT(height >= 0);
+ SkImageInfo info = {
+ width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
+ };
+ return info;
+ }
+
bool isOpaque() const {
return SkAlphaTypeIsOpaque(fAlphaType);
}
diff --git a/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp b/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp
index 65f622883d..dec529ff3c 100644
--- a/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp
+++ b/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp
@@ -26,9 +26,7 @@ JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv*
AndroidBitmap_getInfo(env, dstBitmap, &dstInfo);
AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels);
- SkImageInfo info = {
- dstInfo.width, dstInfo.height, kPMColor_SkColorType, kPremul_SkAlphaType
- };
+ SkImageInfo info = SkImageInfo::MakeN32Premul(dstInfo.width, dstInfo.height);
// Create a surface from the given bitmap
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride));
diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp
index c6fc67f3cc..8b486bd016 100644
--- a/samplecode/SampleFatBits.cpp
+++ b/samplecode/SampleFatBits.cpp
@@ -106,9 +106,7 @@ public:
fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
fShader->setLocalMatrix(fMatrix);
- SkImageInfo info = {
- width, height, kPMColor_SkColorType, kPremul_SkAlphaType
- };
+ SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
fMinSurface.reset(SkSurface::NewRaster(info));
info.fWidth *= zoom;
info.fHeight *= zoom;
diff --git a/src/core/SkImageFilterUtils.cpp b/src/core/SkImageFilterUtils.cpp
index 92fe67e84c..204f38d65b 100644
--- a/src/core/SkImageFilterUtils.cpp
+++ b/src/core/SkImageFilterUtils.cpp
@@ -15,12 +15,7 @@
#include "SkGr.h"
bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
- SkImageInfo info = {
- width,
- height,
- kPMColor_SkColorType,
- kPremul_SkAlphaType,
- };
+ SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
result->setConfig(info);
result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
return true;
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp
index fc3148bdd8..d87597315f 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -293,13 +293,8 @@ bool SkScaledImageCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap,
return false;
}
- SkImageInfo info = {
- bitmap->width(),
- bitmap->height(),
- kPMColor_SkColorType,
- bitmap->alphaType()
- };
-
+ SkImageInfo info = SkImageInfo::MakeN32(bitmap->width(), bitmap->height(),
+ bitmap->alphaType());
bitmap->setPixelRef(SkNEW_ARGS(SkOneShotDiscardablePixelRef,
(info, dm, bitmap->rowBytes())))->unref();
bitmap->lockPixels();
diff --git a/tests/MallocPixelRefTest.cpp b/tests/MallocPixelRefTest.cpp
index bf8f16df5f..5c28ac89cb 100644
--- a/tests/MallocPixelRefTest.cpp
+++ b/tests/MallocPixelRefTest.cpp
@@ -22,7 +22,7 @@ static void set_to_one_proc(void*, void* context) {
*/
DEF_TEST(MallocPixelRef, reporter) {
REPORTER_ASSERT(reporter, true);
- SkImageInfo info = {10, 13, kPMColor_SkColorType, kPremul_SkAlphaType};
+ SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13);
{
SkAutoTUnref<SkMallocPixelRef> pr(
SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, NULL));
diff --git a/tests/PixelRefTest.cpp b/tests/PixelRefTest.cpp
index 3c735c6423..d7fe9f47aa 100644
--- a/tests/PixelRefTest.cpp
+++ b/tests/PixelRefTest.cpp
@@ -50,7 +50,7 @@ private:
} // namespace
DEF_TEST(PixelRef_GenIDChange, r) {
- SkImageInfo info = { 10, 10, kPMColor_SkColorType, kPremul_SkAlphaType };
+ SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NULL));