mobile/android/base/gfx/CairoUtils.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 package org.mozilla.gecko.gfx;
michael@0 7
michael@0 8 import android.graphics.Bitmap;
michael@0 9
michael@0 10 /**
michael@0 11 * Utility methods useful when displaying Cairo bitmaps using OpenGL ES.
michael@0 12 */
michael@0 13 public class CairoUtils {
michael@0 14 private CairoUtils() { /* Don't call me. */ }
michael@0 15
michael@0 16 public static int bitsPerPixelForCairoFormat(int cairoFormat) {
michael@0 17 switch (cairoFormat) {
michael@0 18 case CairoImage.FORMAT_A1: return 1;
michael@0 19 case CairoImage.FORMAT_A8: return 8;
michael@0 20 case CairoImage.FORMAT_RGB16_565: return 16;
michael@0 21 case CairoImage.FORMAT_RGB24: return 24;
michael@0 22 case CairoImage.FORMAT_ARGB32: return 32;
michael@0 23 default:
michael@0 24 throw new RuntimeException("Unknown Cairo format");
michael@0 25 }
michael@0 26 }
michael@0 27
michael@0 28 public static int bitmapConfigToCairoFormat(Bitmap.Config config) {
michael@0 29 if (config == null)
michael@0 30 return CairoImage.FORMAT_ARGB32; /* Droid Pro fix. */
michael@0 31
michael@0 32 switch (config) {
michael@0 33 case ALPHA_8: return CairoImage.FORMAT_A8;
michael@0 34 case ARGB_4444: throw new RuntimeException("ARGB_444 unsupported");
michael@0 35 case ARGB_8888: return CairoImage.FORMAT_ARGB32;
michael@0 36 case RGB_565: return CairoImage.FORMAT_RGB16_565;
michael@0 37 default: throw new RuntimeException("Unknown Skia bitmap config");
michael@0 38 }
michael@0 39 }
michael@0 40
michael@0 41 public static Bitmap.Config cairoFormatTobitmapConfig(int format) {
michael@0 42 switch (format) {
michael@0 43 case CairoImage.FORMAT_A8: return Bitmap.Config.ALPHA_8;
michael@0 44 case CairoImage.FORMAT_ARGB32: return Bitmap.Config.ARGB_8888;
michael@0 45 case CairoImage.FORMAT_RGB16_565: return Bitmap.Config.RGB_565;
michael@0 46 default:
michael@0 47 throw new RuntimeException("Unknown CairoImage format");
michael@0 48 }
michael@0 49 }
michael@0 50 }
michael@0 51

mercurial