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
This commit is contained in:
commit-bot@chromium.org 2014-01-15 02:38:22 +00:00
parent 78f6ddc1a0
commit 32678d9a45
9 changed files with 59 additions and 30 deletions

View File

@ -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));

View File

@ -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()) {

View File

@ -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);
}

View File

@ -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));

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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));

View File

@ -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));