michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.gfx; michael@0: michael@0: import android.graphics.Bitmap; michael@0: michael@0: /** michael@0: * Utility methods useful when displaying Cairo bitmaps using OpenGL ES. michael@0: */ michael@0: public class CairoUtils { michael@0: private CairoUtils() { /* Don't call me. */ } michael@0: michael@0: public static int bitsPerPixelForCairoFormat(int cairoFormat) { michael@0: switch (cairoFormat) { michael@0: case CairoImage.FORMAT_A1: return 1; michael@0: case CairoImage.FORMAT_A8: return 8; michael@0: case CairoImage.FORMAT_RGB16_565: return 16; michael@0: case CairoImage.FORMAT_RGB24: return 24; michael@0: case CairoImage.FORMAT_ARGB32: return 32; michael@0: default: michael@0: throw new RuntimeException("Unknown Cairo format"); michael@0: } michael@0: } michael@0: michael@0: public static int bitmapConfigToCairoFormat(Bitmap.Config config) { michael@0: if (config == null) michael@0: return CairoImage.FORMAT_ARGB32; /* Droid Pro fix. */ michael@0: michael@0: switch (config) { michael@0: case ALPHA_8: return CairoImage.FORMAT_A8; michael@0: case ARGB_4444: throw new RuntimeException("ARGB_444 unsupported"); michael@0: case ARGB_8888: return CairoImage.FORMAT_ARGB32; michael@0: case RGB_565: return CairoImage.FORMAT_RGB16_565; michael@0: default: throw new RuntimeException("Unknown Skia bitmap config"); michael@0: } michael@0: } michael@0: michael@0: public static Bitmap.Config cairoFormatTobitmapConfig(int format) { michael@0: switch (format) { michael@0: case CairoImage.FORMAT_A8: return Bitmap.Config.ALPHA_8; michael@0: case CairoImage.FORMAT_ARGB32: return Bitmap.Config.ARGB_8888; michael@0: case CairoImage.FORMAT_RGB16_565: return Bitmap.Config.RGB_565; michael@0: default: michael@0: throw new RuntimeException("Unknown CairoImage format"); michael@0: } michael@0: } michael@0: } michael@0: