}
SkColorTable* ctable = new SkColorTable(colorsPM, 4);
- bm->setConfig(SkBitmap::kIndex8_Config, 2, 2);
- bm->allocPixels(ctable);
+ bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType,
+ kPremul_SkAlphaType),
+ NULL, ctable);
ctable->unref();
*bm->getAddr8(0, 0) = 0;
static const int PIXEL_SIZE_8888 = SLIDE_SIZE / 256;
static const int PIXEL_SIZE_4444 = SLIDE_SIZE / 16;
-static void init_bitmap(SkBitmap::Config config, SkBitmap* bitmap) {
- bitmap->allocConfigPixels(config, SLIDE_SIZE, SLIDE_SIZE);
+static void init_bitmap(SkColorType ct, SkBitmap* bitmap) {
+ bitmap->allocPixels(SkImageInfo::Make(SLIDE_SIZE, SLIDE_SIZE, ct,
+ kPremul_SkAlphaType));
bitmap->eraseColor(SK_ColorWHITE);
}
static SkBitmap make_argb8888_gradient() {
SkBitmap bitmap;
- init_bitmap(SkBitmap::kARGB_8888_Config, &bitmap);
+ init_bitmap(kPMColor_SkColorType, &bitmap);
uint8_t rowColor = 0;
for (int y = 0; y < SLIDE_SIZE; y++) {
uint32_t* dst = bitmap.getAddr32(0, y);
static SkBitmap make_argb4444_gradient() {
SkBitmap bitmap;
- init_bitmap(SkBitmap::kARGB_4444_Config, &bitmap);
+ init_bitmap(kARGB_4444_SkColorType, &bitmap);
uint8_t rowColor = 0;
for (int y = 0; y < SLIDE_SIZE; y++) {
uint16_t* dst = bitmap.getAddr16(0, y);
static SkBitmap make_argb8888_stripes() {
SkBitmap bitmap;
- init_bitmap(SkBitmap::kARGB_8888_Config, &bitmap);
+ init_bitmap(kPMColor_SkColorType, &bitmap);
uint8_t rowColor = 0;
for (int y = 0; y < SLIDE_SIZE; y++) {
uint32_t* dst = bitmap.getAddr32(0, y);
static SkBitmap make_argb4444_stripes() {
SkBitmap bitmap;
- init_bitmap(SkBitmap::kARGB_4444_Config, &bitmap);
+ init_bitmap(kARGB_4444_SkColorType, &bitmap);
uint8_t rowColor = 0;;
for (int y = 0; y < SLIDE_SIZE; y++) {
uint16_t* dst = bitmap.getAddr16(0, y);
SkPaint circlePaint;
circlePaint.setColor(SK_ColorBLACK);
- bm->allocConfigPixels(SkBitmap::kA8_Config, 20, 20);
+ bm->allocPixels(SkImageInfo::MakeA8(20, 20));
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
SkAutoMaskFreeImage amfi(mask.fImage);
SkBitmap bm;
- bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height());
- bm.setPixels(mask.fImage);
+ bm.installMaskPixels(mask);
center_x = (canvas_size.fWidth - mask.fBounds.width())/2;
center_y = (canvas_size.fHeight - mask.fBounds.height())/2;
return bm;
}
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
- bm->allocConfigPixels(config, w, h);
+static void makebm(SkBitmap* bm, int w, int h) {
+ bm->allocN32Pixels(w, h);
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
virtual void onDraw(SkCanvas* canvas) {
static const int kBmpSize = 2048;
if (fLargeBitmap.isNull()) {
- makebm(&fLargeBitmap,
- SkBitmap::kARGB_8888_Config,
- kBmpSize, kBmpSize);
+ makebm(&fLargeBitmap, kBmpSize, kBmpSize);
}
SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
static const int kMaxSrcRectSize = 1 << (SkNextLog2(kBmpSize) + 2);
otherwise on compare we may not get a perfect match.
*/
static void force_all_opaque(const SkBitmap& bitmap) {
- SkBitmap::Config config = bitmap.config();
- switch (config) {
- case SkBitmap::kARGB_8888_Config:
+ SkColorType colorType = bitmap.colorType();
+ switch (colorType) {
+ case kPMColor_SkColorType:
force_all_opaque_8888(bitmap);
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
// nothing to do here; 565 bitmaps are inherently opaque
break;
default:
- gm_fprintf(stderr, "unsupported bitmap config %d\n", config);
+ gm_fprintf(stderr, "unsupported bitmap colorType %d\n", colorType);
DEBUGFAIL_SEE_STDERR;
}
}
// the device is as large as the current rendertarget, so
// we explicitly only readback the amount we expect (in
// size) overwrite our previous allocation
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
- size.fHeight);
+ bitmap->setConfig(SkImageInfo::MakeN32Premul(size.fWidth, size.fHeight));
canvas->readPixels(bitmap, 0, 0);
}
#endif
return;
}
- if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) ||
- (SkBitmap::kARGB_8888_Config != actualBitmap.config())) {
+ if ((kPMColor_SkColorType != expectedBitmap.colorType()) ||
+ (kPMColor_SkColorType != actualBitmap.colorType())) {
gm_fprintf(stderr, "---- %s: not computing max per-channel"
" pixel mismatch because non-8888\n", testName);
return;
namespace skiagm {
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
- bm->allocConfigPixels(config, w, h);
+static void makebm(SkBitmap* bm, int w, int h) {
+ bm->allocN32Pixels(w, h);
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
int w, int h) {
static SkBitmap bmp;
if (bmp.isNull()) {
- makebm(&bmp, SkBitmap::kARGB_8888_Config, w/2, h/4);
+ makebm(&bmp, w/2, h/4);
}
return SkShader::CreateBitmapShader(bmp, tx, ty);
}
namespace skiagm {
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
- bm->allocConfigPixels(config, w, h);
+static void makebm(SkBitmap* bm, int w, int h) {
+ bm->allocN32Pixels(w, h);
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
static SkBitmap bmp;
if (bmp.isNull()) {
- makebm(&bmp, SkBitmap::kARGB_8888_Config, kPointSize / 2, kPointSize / 2);
+ makebm(&bmp, kPointSize / 2, kPointSize / 2);
}
SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(bmp,
namespace skiagm {
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
- bm->allocConfigPixels(config, w, h);
+static void makebm(SkBitmap* bm, int w, int h) {
+ bm->allocN32Pixels(w, h);
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
static SkBitmap bmp;
if (bmp.isNull()) {
- makebm(&bmp, SkBitmap::kARGB_8888_Config, kPointSize / 4, kPointSize / 4);
+ makebm(&bmp, kPointSize / 4, kPointSize / 4);
}
SkPaint bmpPaint;
SkAutoMaskFreeImage amfi(mask.fImage);
- bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(),
- mask.fBounds.height(), mask.fRowBytes);
- bm.setPixels(mask.fImage);
+ bm.installMaskPixels(mask);
// need to copy for deferred drawing test to work
SkBitmap bm2;
#include "SkUnitMappers.h"
#include "SkBlurDrawLooper.h"
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
- bm->allocConfigPixels(config, w, h);
+static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
+ bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
paint->setFilterLevel(filter ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
}
-static const SkBitmap::Config gConfigs[] = {
- SkBitmap::kARGB_8888_Config,
- SkBitmap::kRGB_565_Config,
+static const SkColorType gColorTypes[] = {
+ kPMColor_SkColorType,
+ kRGB_565_SkColorType,
};
class TilingGM : public skiagm::GM {
: fPowerOfTwoSize(powerOfTwoSize) {
}
- SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)];
+ SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)];
protected:
virtual void onOnceBeforeDraw() SK_OVERRIDE {
int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
- for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
- makebm(&fTexture[i], gConfigs[i], size, size);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
+ makebm(&fTexture[i], gColorTypes[i], size, size);
}
}
y += SkIntToScalar(16);
- for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) {
x = SkIntToScalar(10);
for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
#if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue
// on SGX where resizing NPOT textures to POT textures exhibits a driver bug.
if (!fPowerOfTwoSize) {
- makebm(&fTexture[i], gConfigs[i], size, size);
+ makebm(&fTexture[i], gColorTypes[i], size, size);
}
#endif
setup(&paint, fTexture[i], gFilters[j], gModes[kx], gModes[ky]);
static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
SkBitmap bm;
- makebm(&bm, SkBitmap::kARGB_8888_Config, gWidth, gHeight);
+ makebm(&bm, kPMColor_SkColorType, gWidth, gHeight);
return SkShader::CreateBitmapShader(bm, tx, ty);
}
#include "SkUnitMappers.h"
#include "SkBlurDrawLooper.h"
-static void makebm(SkBitmap* bm, SkBitmap::Config config, int w, int h) {
- bm->allocConfigPixels(config, w, h);
+static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
+ bm->allocPixels(SkImageInfo::Make(w, h, ct, kPremul_SkAlphaType));
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
paint->setFilterLevel(filter_level);
}
-static const SkBitmap::Config gConfigs[] = {
- SkBitmap::kARGB_8888_Config,
- SkBitmap::kRGB_565_Config,
+static const SkColorType gColorTypes[] = {
+ kPMColor_SkColorType,
+ kRGB_565_SkColorType,
};
class ScaledTilingGM : public skiagm::GM {
, fPowerOfTwoSize(powerOfTwoSize) {
}
- SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)];
+ SkBitmap fTexture[SK_ARRAY_COUNT(gColorTypes)];
protected:
virtual void onOnceBeforeDraw() SK_OVERRIDE {
int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
- for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
- makebm(&fTexture[i], gConfigs[i], size, size);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
+ makebm(&fTexture[i], gColorTypes[i], size, size);
}
}
SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) };
- static const char* gConfigNames[] = { "8888" , "565", "4444" };
+ static const char* gColorTypeNames[] = { "8888" , "565", "4444" };
static const SkPaint::FilterLevel gFilterLevels[] =
{ SkPaint::kNone_FilterLevel,
y = SkIntToScalar(40) / scale;
- for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gColorTypes); i++) {
for (size_t j = 0; j < SK_ARRAY_COUNT(gFilterLevels); j++) {
x = SkIntToScalar(10)/scale;
for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
#if 1 // Temporary change to regen bitmap before each draw. This may help tracking down an issue
// on SGX where resizing NPOT textures to POT textures exhibits a driver bug.
if (!fPowerOfTwoSize) {
- makebm(&fTexture[i], gConfigs[i], size, size);
+ makebm(&fTexture[i], gColorTypes[i], size, size);
}
#endif
setup(&paint, fTexture[i], gFilterLevels[j], gModes[kx], gModes[ky]);
SkString str;
p.setAntiAlias(true);
p.setLooper(&fLooper);
- str.printf("%s, %s", gConfigNames[i], gFilterNames[j]);
+ str.printf("%s, %s", gColorTypeNames[i], gFilterNames[j]);
canvas->drawText(str.c_str(), str.size(), scale*x, scale*(y + r.height() * 2 / 3), p);
}
static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
SkBitmap bm;
- makebm(&bm, SkBitmap::kARGB_8888_Config, gWidth, gHeight);
+ makebm(&bm, kPMColor_SkColorType, gWidth, gHeight);
return SkShader::CreateBitmapShader(bm, tx, ty);
}
SkColorTable* ctable = new SkColorTable(c, SK_ARRAY_COUNT(c));
SkBitmap bm;
- bm.setConfig(SkBitmap::kIndex8_Config, 1, 1);
- bm.allocPixels(ctable);
+ bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
+ kPremul_SkAlphaType),
+ NULL, ctable);
ctable->unref();
bm.lockPixels();
c.drawOval(r, p);
}
- dst->setConfig(SkBitmap::kARGB_8888_Config, w, h);
- dst->allocPixels();
+ dst->allocN32Pixels(w, h);
dst->eraseColor(SK_ColorTRANSPARENT);
{
c.drawRect(r, p);
}
- transparent->setConfig(SkBitmap::kARGB_8888_Config, w, h);
- transparent->allocPixels();
+ transparent->allocN32Pixels(w, h);
transparent->eraseColor(SK_ColorTRANSPARENT);
}
}
virtual void onOnceBeforeDraw() SK_OVERRIDE {
- fBG.setConfig(SkBitmap::kARGB_4444_Config, 2, 2, 4, kOpaque_SkAlphaType);
- fBG.setPixels(gData);
+ fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
+ kOpaque_SkAlphaType),
+ gData, 4);
make_bitmaps(W, H, &fSrcB, &fDstB, &fTransparent);
}
#include "SkPoint.h"
#include "SkRefCnt.h"
+struct SkMask;
struct SkIRect;
struct SkRect;
class SkPaint;
bool installPixels(const SkImageInfo&, void* pixels, size_t rowBytes,
void (*ReleaseProc)(void* addr, void* context),
void* context);
+
+ /**
+ * Call installPixels with no ReleaseProc specified. This means that the
+ * caller must ensure that the specified pixels are valid for the lifetime
+ * of the created bitmap (and its pixelRef).
+ */
+ bool installPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
+ return this->installPixels(info, pixels, rowBytes, NULL, NULL);
+ }
+
+ /**
+ * Calls installPixels() with the value in the SkMask. The caller must
+ * ensure that the specified mask pixels are valid for the lifetime
+ * of the created bitmap (and its pixelRef).
+ */
+ bool installMaskPixels(const SkMask&);
/**
* DEPRECATED: call info().
clip.copyToMask(&mask);
SkAutoMaskFreeImage amfi(mask.fImage);
- bm.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(),
- mask.fBounds.height()),
- mask.fImage, mask.fRowBytes, NULL, NULL);
+ bm.installMaskPixels(mask);
SkPaint paint;
canvas->drawBitmap(bm,
return true;
}
+bool SkBitmap::installMaskPixels(const SkMask& mask) {
+ if (SkMask::kA8_Format != mask.fFormat) {
+ this->reset();
+ return false;
+ }
+ return this->installPixels(SkImageInfo::MakeA8(mask.fBounds.width(),
+ mask.fBounds.height()),
+ mask.fImage, mask.fRowBytes);
+}
+
bool SkBitmap::allocConfigPixels(Config config, int width, int height,
bool isOpaque) {
SkColorType ct;
// FIXME: This code duplicates code in draw_rects_into_mask, below. Is there a
// clean way to share more code?
SkBitmap bitmap;
- bitmap.installPixels(SkImageInfo::MakeA8(mask->fBounds.width(),
- mask->fBounds.height()),
- mask->fImage, mask->fRowBytes, NULL, NULL);
+ bitmap.installMaskPixels(*mask);
SkCanvas canvas(bitmap);
canvas.translate(-SkIntToScalar(mask->fBounds.left()),
translatedMatrix.postTranslate(-SkIntToScalar(mask->fBounds.fLeft),
-SkIntToScalar(mask->fBounds.fTop));
- device.installPixels(SkImageInfo::MakeA8(mask->fBounds.width(),
- mask->fBounds.height()),
- mask->fImage, mask->fRowBytes, NULL, NULL);
+ device.installMaskPixels(*mask);
draw.fBitmap = &device;
draw.fMatrix = &drawMatrix;