mobile/android/base/gfx/CairoUtils.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial