stop using (deprecated) SkBitmap::Config
Change-Id: Ic75b5fc6996578e9d95bd3a220439ec1541d7c3b
This commit is contained in:
@@ -52,13 +52,13 @@ static void usage(const char* pname)
|
||||
);
|
||||
}
|
||||
|
||||
static SkBitmap::Config flinger2skia(PixelFormat f)
|
||||
static SkColorType flinger2skia(PixelFormat f)
|
||||
{
|
||||
switch (f) {
|
||||
case PIXEL_FORMAT_RGB_565:
|
||||
return SkBitmap::kRGB_565_Config;
|
||||
return kRGB_565_SkColorType;
|
||||
default:
|
||||
return SkBitmap::kARGB_8888_Config;
|
||||
return kN32_SkColorType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,9 +174,10 @@ int main(int argc, char** argv)
|
||||
|
||||
if (base) {
|
||||
if (png) {
|
||||
const SkImageInfo info = SkImageInfo::Make(w, h, flinger2skia(f),
|
||||
kPremul_SkAlphaType);
|
||||
SkBitmap b;
|
||||
b.setConfig(flinger2skia(f), w, h, s*bytesPerPixel(f));
|
||||
b.setPixels((void*)base);
|
||||
b.installPixels(info, const_cast<void*>(base), s*bytesPerPixel(f));
|
||||
SkDynamicMemoryWStream stream;
|
||||
SkImageEncoder::EncodeStream(&stream, b,
|
||||
SkImageEncoder::kPNG_Type, SkImageEncoder::kDefaultQuality);
|
||||
|
||||
@@ -258,16 +258,16 @@ static void ToColor_SI8_Opaque(SkColor dst[], const void* src, int width,
|
||||
|
||||
// can return NULL
|
||||
static ToColorProc ChooseToColorProc(const SkBitmap& src, bool isPremultiplied) {
|
||||
switch (src.config()) {
|
||||
case SkBitmap::kARGB_8888_Config:
|
||||
switch (src.colorType()) {
|
||||
case kN32_SkColorType:
|
||||
if (src.isOpaque()) return ToColor_S32_Opaque;
|
||||
return isPremultiplied ? ToColor_S32_Alpha : ToColor_S32_Raw;
|
||||
case SkBitmap::kARGB_4444_Config:
|
||||
case kARGB_4444_SkColorType:
|
||||
if (src.isOpaque()) return ToColor_S4444_Opaque;
|
||||
return isPremultiplied ? ToColor_S4444_Alpha : ToColor_S4444_Raw;
|
||||
case SkBitmap::kRGB_565_Config:
|
||||
case kRGB_565_SkColorType:
|
||||
return ToColor_S565;
|
||||
case SkBitmap::kIndex8_Config:
|
||||
case kIndex_8_SkColorType:
|
||||
if (src.getColorTable() == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -291,7 +291,7 @@ static int getPremulBitmapCreateFlags(bool isMutable) {
|
||||
static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors,
|
||||
jint offset, jint stride, jint width, jint height,
|
||||
jint configHandle, jboolean isMutable) {
|
||||
SkBitmap::Config config = static_cast<SkBitmap::Config>(configHandle);
|
||||
SkColorType colorType = SkBitmapConfigToColorType(static_cast<SkBitmap::Config>(configHandle));
|
||||
if (NULL != jColors) {
|
||||
size_t n = env->GetArrayLength(jColors);
|
||||
if (n < SkAbs32(stride) * (size_t)height) {
|
||||
@@ -301,12 +301,12 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors,
|
||||
}
|
||||
|
||||
// ARGB_4444 is a deprecated format, convert automatically to 8888
|
||||
if (config == SkBitmap::kARGB_4444_Config) {
|
||||
config = SkBitmap::kARGB_8888_Config;
|
||||
if (colorType == kARGB_4444_SkColorType) {
|
||||
colorType = kN32_SkColorType;
|
||||
}
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(config, width, height);
|
||||
bitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType));
|
||||
|
||||
jbyteArray buff = GraphicsJNI::allocateJavaPixelRef(env, &bitmap, NULL);
|
||||
if (NULL == buff) {
|
||||
@@ -515,28 +515,29 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
|
||||
|
||||
android::Parcel* p = android::parcelForJavaObject(env, parcel);
|
||||
|
||||
const bool isMutable = p->readInt32() != 0;
|
||||
const SkBitmap::Config config = (SkBitmap::Config)p->readInt32();
|
||||
const int width = p->readInt32();
|
||||
const int height = p->readInt32();
|
||||
const int rowBytes = p->readInt32();
|
||||
const int density = p->readInt32();
|
||||
const bool isMutable = p->readInt32() != 0;
|
||||
const SkColorType colorType = (SkColorType)p->readInt32();
|
||||
const SkAlphaType alphaType = (SkAlphaType)p->readInt32();
|
||||
const int width = p->readInt32();
|
||||
const int height = p->readInt32();
|
||||
const int rowBytes = p->readInt32();
|
||||
const int density = p->readInt32();
|
||||
|
||||
if (SkBitmap::kARGB_8888_Config != config &&
|
||||
SkBitmap::kRGB_565_Config != config &&
|
||||
SkBitmap::kARGB_4444_Config != config &&
|
||||
SkBitmap::kIndex8_Config != config &&
|
||||
SkBitmap::kA8_Config != config) {
|
||||
SkDebugf("Bitmap_createFromParcel unknown config: %d\n", config);
|
||||
if (kN32_SkColorType != colorType &&
|
||||
kRGB_565_SkColorType != colorType &&
|
||||
kARGB_4444_SkColorType != colorType &&
|
||||
kIndex_8_SkColorType != colorType &&
|
||||
kAlpha_8_SkColorType != colorType) {
|
||||
SkDebugf("Bitmap_createFromParcel unknown colortype: %d\n", colorType);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkBitmap* bitmap = new SkBitmap;
|
||||
|
||||
bitmap->setConfig(config, width, height, rowBytes);
|
||||
bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes);
|
||||
|
||||
SkColorTable* ctable = NULL;
|
||||
if (config == SkBitmap::kIndex8_Config) {
|
||||
if (colorType == kIndex_8_SkColorType) {
|
||||
int count = p->readInt32();
|
||||
if (count > 0) {
|
||||
size_t size = count * sizeof(SkPMColor);
|
||||
@@ -587,13 +588,14 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
|
||||
android::Parcel* p = android::parcelForJavaObject(env, parcel);
|
||||
|
||||
p->writeInt32(isMutable);
|
||||
p->writeInt32(bitmap->config());
|
||||
p->writeInt32(bitmap->colorType());
|
||||
p->writeInt32(bitmap->alphaType());
|
||||
p->writeInt32(bitmap->width());
|
||||
p->writeInt32(bitmap->height());
|
||||
p->writeInt32(bitmap->rowBytes());
|
||||
p->writeInt32(density);
|
||||
|
||||
if (bitmap->config() == SkBitmap::kIndex8_Config) {
|
||||
if (bitmap->colorType() == kIndex_8_SkColorType) {
|
||||
SkColorTable* ctable = bitmap->getColorTable();
|
||||
if (ctable != NULL) {
|
||||
int count = ctable->count();
|
||||
|
||||
@@ -386,7 +386,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
|
||||
// FIXME: If the alphaType is kUnpremul and the image has alpha, the
|
||||
// colors may not be correct, since Skia does not yet support drawing
|
||||
// to/from unpremultiplied bitmaps.
|
||||
outputBitmap->setConfig(SkImageInfo::Make(scaledWidth, scaledHeight,
|
||||
outputBitmap->setInfo(SkImageInfo::Make(scaledWidth, scaledHeight,
|
||||
colorType, decodingBitmap.alphaType()));
|
||||
if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
|
||||
return nullObjectReturn("allocation failed for scaled bitmap");
|
||||
|
||||
@@ -703,10 +703,11 @@ public:
|
||||
jboolean hasAlpha, jlong paintHandle) {
|
||||
SkCanvas* canvas = getNativeCanvas(canvasHandle);
|
||||
SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
|
||||
SkImageInfo info = SkImageInfo::Make(width, height,
|
||||
hasAlpha ? kN32_SkColorType : kRGB_565_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(hasAlpha ? SkBitmap::kARGB_8888_Config :
|
||||
SkBitmap::kRGB_565_Config, width, height);
|
||||
if (!bitmap.allocPixels()) {
|
||||
if (!bitmap.allocPixels(info)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -388,11 +388,11 @@ static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject claz
|
||||
static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz,
|
||||
jlong rendererPtr, jintArray colors, jint offset, jint stride,
|
||||
jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, jlong paintPtr) {
|
||||
const SkImageInfo info = SkImageInfo::Make(width, height,
|
||||
hasAlpha ? kN32_SkColorType : kRGB_565_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
SkBitmap* bitmap = new SkBitmap;
|
||||
bitmap->setConfig(hasAlpha ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config,
|
||||
width, height);
|
||||
|
||||
if (!bitmap->allocPixels()) {
|
||||
if (!bitmap->allocPixels(info)) {
|
||||
delete bitmap;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,16 +142,16 @@ static void android_view_GraphiceBuffer_destroy(JNIEnv* env, jobject clazz,
|
||||
// Canvas management
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static inline SkBitmap::Config convertPixelFormat(int32_t format) {
|
||||
static inline SkColorType convertPixelFormat(int32_t format) {
|
||||
switch (format) {
|
||||
case PIXEL_FORMAT_RGBA_8888:
|
||||
return SkBitmap::kARGB_8888_Config;
|
||||
return kN32_SkColorType;
|
||||
case PIXEL_FORMAT_RGBX_8888:
|
||||
return SkBitmap::kARGB_8888_Config;
|
||||
return kN32_SkColorType;
|
||||
case PIXEL_FORMAT_RGB_565:
|
||||
return SkBitmap::kRGB_565_Config;
|
||||
return kRGB_565_SkColorType;
|
||||
default:
|
||||
return SkBitmap::kNo_Config;
|
||||
return kUnknown_SkColorType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +188,10 @@ static jboolean android_view_GraphicBuffer_lockCanvas(JNIEnv* env, jobject,
|
||||
ssize_t bytesCount = buffer->getStride() * bytesPerPixel(buffer->getPixelFormat());
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(convertPixelFormat(buffer->getPixelFormat()),
|
||||
buffer->getWidth(), buffer->getHeight(), bytesCount);
|
||||
bitmap.setInfo(SkImageInfo::Make(buffer->getWidth(), buffer->getHeight(),
|
||||
convertPixelFormat(buffer->getPixelFormat()),
|
||||
kPremul_SkAlphaType),
|
||||
bytesCount);
|
||||
|
||||
if (buffer->getWidth() > 0 && buffer->getHeight() > 0) {
|
||||
bitmap.setPixels(bits);
|
||||
|
||||
@@ -173,17 +173,17 @@ static jboolean nativeIsConsumerRunningBehind(JNIEnv* env, jclass clazz, jlong n
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline SkBitmap::Config convertPixelFormat(PixelFormat format) {
|
||||
static inline SkColorType convertPixelFormat(PixelFormat format) {
|
||||
/* note: if PIXEL_FORMAT_RGBX_8888 means that all alpha bytes are 0xFF, then
|
||||
we can map to SkBitmap::kARGB_8888_Config, and optionally call
|
||||
we can map to kN32_SkColorType, and optionally call
|
||||
bitmap.setAlphaType(kOpaque_SkAlphaType) on the resulting SkBitmap
|
||||
(as an accelerator)
|
||||
*/
|
||||
switch (format) {
|
||||
case PIXEL_FORMAT_RGBX_8888: return SkBitmap::kARGB_8888_Config;
|
||||
case PIXEL_FORMAT_RGBA_8888: return SkBitmap::kARGB_8888_Config;
|
||||
case PIXEL_FORMAT_RGB_565: return SkBitmap::kRGB_565_Config;
|
||||
default: return SkBitmap::kNo_Config;
|
||||
case PIXEL_FORMAT_RGBX_8888: return kN32_SkColorType;
|
||||
case PIXEL_FORMAT_RGBA_8888: return kN32_SkColorType;
|
||||
case PIXEL_FORMAT_RGB_565: return kRGB_565_SkColorType;
|
||||
default: return kUnknown_SkColorType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,12 +220,16 @@ static jlong nativeLockCanvas(JNIEnv* env, jclass clazz,
|
||||
// Associate a SkCanvas object to this surface
|
||||
env->SetIntField(canvasObj, gCanvasClassInfo.mSurfaceFormat, outBuffer.format);
|
||||
|
||||
SkImageInfo info = SkImageInfo::Make(outBuffer.width, outBuffer.height,
|
||||
convertPixelFormat(outBuffer.format),
|
||||
kPremul_SkAlphaType);
|
||||
if (outBuffer.format == PIXEL_FORMAT_RGBX_8888) {
|
||||
info.fAlphaType = kOpaque_SkAlphaType;
|
||||
}
|
||||
|
||||
SkBitmap bitmap;
|
||||
ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
|
||||
bitmap.setConfig(convertPixelFormat(outBuffer.format), outBuffer.width, outBuffer.height, bpr);
|
||||
if (outBuffer.format == PIXEL_FORMAT_RGBX_8888) {
|
||||
bitmap.setAlphaType(kOpaque_SkAlphaType);
|
||||
}
|
||||
bitmap.setInfo(info, bpr);
|
||||
if (outBuffer.width > 0 && outBuffer.height > 0) {
|
||||
bitmap.setPixels(outBuffer.bits);
|
||||
} else {
|
||||
|
||||
@@ -175,7 +175,7 @@ static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
|
||||
screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
|
||||
|
||||
SkBitmap* bitmap = new SkBitmap();
|
||||
bitmap->setConfig(screenshotInfo, (size_t)rowBytes);
|
||||
bitmap->setInfo(screenshotInfo, (size_t)rowBytes);
|
||||
if (screenshotInfo.fWidth > 0 && screenshotInfo.fHeight > 0) {
|
||||
// takes ownership of ScreenshotClient
|
||||
SkMallocPixelRef* pixels = SkMallocPixelRef::NewWithProc(screenshotInfo,
|
||||
|
||||
@@ -73,17 +73,28 @@ static struct {
|
||||
// Native layer
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static inline SkBitmap::Config convertPixelFormat(int32_t format) {
|
||||
switch (format) {
|
||||
// FIXME: consider exporting this to share (e.g. android_view_Surface.cpp)
|
||||
static inline SkImageInfo convertPixelFormat(const ANativeWindow_Buffer& buffer) {
|
||||
SkImageInfo info;
|
||||
info.fWidth = buffer.width;
|
||||
info.fHeight = buffer.height;
|
||||
switch (buffer.format) {
|
||||
case WINDOW_FORMAT_RGBA_8888:
|
||||
return SkBitmap::kARGB_8888_Config;
|
||||
info.fColorType = kN32_SkColorType;
|
||||
info.fAlphaType = kPremul_SkAlphaType;
|
||||
break;
|
||||
case WINDOW_FORMAT_RGBX_8888:
|
||||
return SkBitmap::kARGB_8888_Config;
|
||||
info.fColorType = kN32_SkColorType;
|
||||
info.fAlphaType = kOpaque_SkAlphaType;
|
||||
case WINDOW_FORMAT_RGB_565:
|
||||
return SkBitmap::kRGB_565_Config;
|
||||
info.fColorType = kRGB_565_SkColorType;
|
||||
info.fAlphaType = kOpaque_SkAlphaType;
|
||||
default:
|
||||
return SkBitmap::kNo_Config;
|
||||
info.fColorType = kUnknown_SkColorType;
|
||||
info.fAlphaType = kIgnore_SkAlphaType;
|
||||
break;
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,11 +159,7 @@ static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
|
||||
ssize_t bytesCount = buffer.stride * bytesPerPixel(buffer.format);
|
||||
|
||||
SkBitmap bitmap;
|
||||
bitmap.setConfig(convertPixelFormat(buffer.format), buffer.width, buffer.height, bytesCount);
|
||||
|
||||
if (buffer.format == WINDOW_FORMAT_RGBX_8888) {
|
||||
bitmap.setAlphaType(kOpaque_SkAlphaType);
|
||||
}
|
||||
bitmap.setInfo(convertPixelFormat(buffer), bytesCount);
|
||||
|
||||
if (buffer.width > 0 && buffer.height > 0) {
|
||||
bitmap.setPixels(buffer.bits);
|
||||
|
||||
@@ -104,8 +104,7 @@ void PathCache::computeBounds(const SkRect& bounds, const SkPaint* paint,
|
||||
}
|
||||
|
||||
static void initBitmap(SkBitmap& bitmap, uint32_t width, uint32_t height) {
|
||||
bitmap.setConfig(SkBitmap::kA8_Config, width, height);
|
||||
bitmap.allocPixels();
|
||||
bitmap.allocPixels(SkImageInfo::MakeA8(width, height));
|
||||
bitmap.eraseColor(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -333,8 +333,7 @@ void TextureCache::generateTexture(const SkBitmap* bitmap, Texture* texture, boo
|
||||
void TextureCache::uploadLoFiTexture(bool resize, const SkBitmap* bitmap,
|
||||
uint32_t width, uint32_t height) {
|
||||
SkBitmap rgbaBitmap;
|
||||
rgbaBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, bitmap->alphaType());
|
||||
rgbaBitmap.allocPixels();
|
||||
rgbaBitmap.allocPixels(SkImageInfo::MakeN32(width, height, bitmap->alphaType()));
|
||||
rgbaBitmap.eraseColor(0);
|
||||
|
||||
SkCanvas canvas(rgbaBitmap);
|
||||
|
||||
@@ -206,9 +206,8 @@ void SpriteController::doUpdateSprites() {
|
||||
} else {
|
||||
SkBitmap surfaceBitmap;
|
||||
ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
|
||||
surfaceBitmap.setConfig(SkBitmap::kARGB_8888_Config,
|
||||
outBuffer.width, outBuffer.height, bpr);
|
||||
surfaceBitmap.setPixels(outBuffer.bits);
|
||||
surfaceBitmap.installPixels(SkImageInfo::MakeN32Premul(outBuffer.width, outBuffer.height),
|
||||
outBuffer.bits, bpr);
|
||||
|
||||
SkCanvas surfaceCanvas(surfaceBitmap);
|
||||
|
||||
|
||||
@@ -169,15 +169,10 @@ bool OmxJpegImageDecoder::decodeSource(sp<MediaSource> decoder,
|
||||
return true;
|
||||
}
|
||||
|
||||
void OmxJpegImageDecoder::configBitmapSize(SkBitmap* bm, SkBitmap::Config pref,
|
||||
void OmxJpegImageDecoder::configBitmapSize(SkBitmap* bm, SkColorType pref,
|
||||
int width, int height) {
|
||||
bm->setConfig(getColorSpaceConfig(pref), width, height, 0, kOpaque_SkAlphaType);
|
||||
}
|
||||
|
||||
SkBitmap::Config OmxJpegImageDecoder::getColorSpaceConfig(
|
||||
SkBitmap::Config pref) {
|
||||
|
||||
// Set the color space to ARGB_8888 for now
|
||||
// Set the color space to ARGB_8888 for now (ignoring pref)
|
||||
// because of limitation in hardware support.
|
||||
return SkBitmap::kARGB_8888_Config;
|
||||
bm->setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,7 @@ private:
|
||||
sp<MediaSource> getDecoder(OMXClient* client, const sp<MediaSource>& source);
|
||||
bool decodeSource(sp<MediaSource> decoder, const sp<MediaSource>& source,
|
||||
SkBitmap* bm);
|
||||
void configBitmapSize(SkBitmap* bm, SkBitmap::Config pref, int width,
|
||||
int height);
|
||||
SkBitmap::Config getColorSpaceConfig(SkBitmap::Config pref);
|
||||
void configBitmapSize(SkBitmap* bm, SkColorType, int width, int height);
|
||||
|
||||
OMXClient mClient;
|
||||
};
|
||||
|
||||
@@ -61,8 +61,7 @@ static jlong com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, job
|
||||
jobject canvas, jint width, jint height) {
|
||||
|
||||
SkBitmap* bitmap = new SkBitmap;
|
||||
bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
|
||||
bitmap->allocPixels();
|
||||
bitmap->allocN32Pixels(width, height);
|
||||
bitmap->eraseColor(0);
|
||||
INVOKEV(canvas, gCanvasClassInfo.setNativeBitmap, reinterpret_cast<jlong>(bitmap));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user