mobile/android/base/gfx/CairoUtils.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/gfx/CairoUtils.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +package org.mozilla.gecko.gfx;
    1.10 +
    1.11 +import android.graphics.Bitmap;
    1.12 +
    1.13 +/**
    1.14 + * Utility methods useful when displaying Cairo bitmaps using OpenGL ES.
    1.15 + */
    1.16 +public class CairoUtils {
    1.17 +    private CairoUtils() { /* Don't call me. */ }
    1.18 +
    1.19 +    public static int bitsPerPixelForCairoFormat(int cairoFormat) {
    1.20 +        switch (cairoFormat) {
    1.21 +        case CairoImage.FORMAT_A1:          return 1;
    1.22 +        case CairoImage.FORMAT_A8:          return 8;
    1.23 +        case CairoImage.FORMAT_RGB16_565:   return 16;
    1.24 +        case CairoImage.FORMAT_RGB24:       return 24;
    1.25 +        case CairoImage.FORMAT_ARGB32:      return 32;
    1.26 +        default:
    1.27 +            throw new RuntimeException("Unknown Cairo format");
    1.28 +        }
    1.29 +    }
    1.30 +
    1.31 +    public static int bitmapConfigToCairoFormat(Bitmap.Config config) {
    1.32 +        if (config == null)
    1.33 +            return CairoImage.FORMAT_ARGB32;    /* Droid Pro fix. */
    1.34 +
    1.35 +        switch (config) {
    1.36 +        case ALPHA_8:   return CairoImage.FORMAT_A8;
    1.37 +        case ARGB_4444: throw new RuntimeException("ARGB_444 unsupported");
    1.38 +        case ARGB_8888: return CairoImage.FORMAT_ARGB32;
    1.39 +        case RGB_565:   return CairoImage.FORMAT_RGB16_565;
    1.40 +        default:        throw new RuntimeException("Unknown Skia bitmap config");
    1.41 +        }
    1.42 +    }
    1.43 +
    1.44 +    public static Bitmap.Config cairoFormatTobitmapConfig(int format) {
    1.45 +        switch (format) {
    1.46 +        case CairoImage.FORMAT_A8:        return Bitmap.Config.ALPHA_8;
    1.47 +        case CairoImage.FORMAT_ARGB32:    return Bitmap.Config.ARGB_8888;
    1.48 +        case CairoImage.FORMAT_RGB16_565: return Bitmap.Config.RGB_565;
    1.49 +        default:
    1.50 +            throw new RuntimeException("Unknown CairoImage format");
    1.51 +        }
    1.52 +    }
    1.53 +}
    1.54 +

mercurial