Support Bitmap.copy for hardware bitmaps
Test: android.uirendering.cts.testclasses.HardwareBitmapTests#testBitmapConfig* bug:30999911 Change-Id: I2e80dff914bfa0666290701072ac93d30d218e8d
This commit is contained in:
@@ -573,6 +573,14 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
|
||||
jint dstConfigHandle, jboolean isMutable) {
|
||||
SkBitmap src;
|
||||
reinterpret_cast<BitmapWrapper*>(srcHandle)->getSkBitmap(&src);
|
||||
if (dstConfigHandle == GraphicsJNI::hardwareLegacyBitmapConfig()) {
|
||||
sk_sp<Bitmap> bitmap(Bitmap::allocateHardwareBitmap(src));
|
||||
if (!bitmap.get()) {
|
||||
return NULL;
|
||||
}
|
||||
return createBitmap(env, bitmap.release(), kBitmapCreateFlag_None);
|
||||
}
|
||||
|
||||
SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle);
|
||||
SkBitmap result;
|
||||
HeapAllocator allocator;
|
||||
|
||||
@@ -583,9 +583,13 @@ public final class Bitmap implements Parcelable {
|
||||
* @param isMutable True if the resulting bitmap should be mutable (i.e.
|
||||
* its pixels can be modified)
|
||||
* @return the new bitmap, or null if the copy could not be made.
|
||||
* @throws IllegalArgumentException if config is {@link Config#HARDWARE} and isMutable is true
|
||||
*/
|
||||
public Bitmap copy(Config config, boolean isMutable) {
|
||||
checkRecycled("Can't copy a recycled bitmap");
|
||||
if (config == Config.HARDWARE && isMutable) {
|
||||
throw new IllegalArgumentException("Hardware bitmaps are always immutable");
|
||||
}
|
||||
Bitmap b = nativeCopy(mNativePtr, config.nativeInt, isMutable);
|
||||
if (b != null) {
|
||||
b.setPremultiplied(mRequestPremultiplied);
|
||||
|
||||
@@ -98,8 +98,6 @@ static sk_sp<Bitmap> allocateHeapBitmap(size_t size, const SkImageInfo& info, si
|
||||
// TODO: handle SRGB sanely
|
||||
static PixelFormat internalFormatToPixelFormat(GLint internalFormat) {
|
||||
switch (internalFormat) {
|
||||
case GL_ALPHA:
|
||||
return PIXEL_FORMAT_TRANSPARENT;
|
||||
case GL_LUMINANCE:
|
||||
return PIXEL_FORMAT_RGBA_8888;
|
||||
case GL_SRGB8_ALPHA8:
|
||||
@@ -215,8 +213,8 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(uirenderer::renderthread::RenderThr
|
||||
}
|
||||
|
||||
const SkImageInfo& info = skBitmap.info();
|
||||
if (info.colorType() == kUnknown_SkColorType) {
|
||||
ALOGW("unable to create hardware bitmap of configuration");
|
||||
if (info.colorType() == kUnknown_SkColorType || info.colorType() == kAlpha_8_SkColorType) {
|
||||
ALOGW("unable to create hardware bitmap of colortype: %d", info.colorType());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -249,7 +247,7 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(uirenderer::renderthread::RenderThr
|
||||
if (!uploadBitmapToGraphicBuffer(caches, bitmap, *buffer, format, type)) {
|
||||
return nullptr;
|
||||
}
|
||||
return sk_sp<Bitmap>(new Bitmap(buffer.get(), info));
|
||||
return sk_sp<Bitmap>(new Bitmap(buffer.get(), bitmap.info()));
|
||||
}
|
||||
|
||||
sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(SkBitmap& bitmap) {
|
||||
@@ -310,7 +308,8 @@ sk_sp<Bitmap> Bitmap::createFrom(sp<GraphicBuffer> graphicBuffer) {
|
||||
return nullptr;
|
||||
}
|
||||
SkImageInfo info = SkImageInfo::Make(graphicBuffer->getWidth(), graphicBuffer->getHeight(),
|
||||
kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
||||
kRGBA_8888_SkColorType, kPremul_SkAlphaType,
|
||||
SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named));
|
||||
return sk_sp<Bitmap>(new Bitmap(graphicBuffer.get(), info));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user