Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ca204e4 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

get rid of PixelFormatInfo and simplify things

Change-Id: I487d4eef7db0095ace4babf5bb100a8769711257
parent 6f7b5891
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -9474,10 +9474,10 @@ package android.graphics {
    ctor public PixelFormat();
    method public static boolean formatHasAlpha(int);
    method public static void getPixelFormatInfo(int, android.graphics.PixelFormat);
    field public static final int A_8 = 8; // 0x8
    field public static final deprecated int A_8 = 8; // 0x8
    field public static final deprecated int JPEG = 256; // 0x100
    field public static final deprecated int LA_88 = 10; // 0xa
    field public static final int L_8 = 9; // 0x9
    field public static final deprecated int L_8 = 9; // 0x9
    field public static final int OPAQUE = -1; // 0xffffffff
    field public static final deprecated int RGBA_4444 = 7; // 0x7
    field public static final deprecated int RGBA_5551 = 6; // 0x6
+0 −1
Original line number Diff line number Diff line
@@ -110,7 +110,6 @@ LOCAL_SRC_FILES:= \
	android/graphics/Path.cpp \
	android/graphics/PathMeasure.cpp \
	android/graphics/PathEffect.cpp \
	android_graphics_PixelFormat.cpp \
	android/graphics/Picture.cpp \
	android/graphics/PorterDuff.cpp \
	android/graphics/BitmapRegionDecoder.cpp \
+0 −2
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ extern int register_android_graphics_Rasterizer(JNIEnv* env);
extern int register_android_graphics_Region(JNIEnv* env);
extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
extern int register_android_graphics_Xfermode(JNIEnv* env);
extern int register_android_graphics_PixelFormat(JNIEnv* env);
extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
extern int register_android_view_GraphicBuffer(JNIEnv* env);
extern int register_android_view_GLES20DisplayList(JNIEnv* env);
@@ -1124,7 +1123,6 @@ static const RegJNIRec gRegJNI[] = {
    REG_JNI(register_android_os_Parcel),
    REG_JNI(register_android_view_DisplayEventReceiver),
    REG_JNI(register_android_nio_utils),
    REG_JNI(register_android_graphics_PixelFormat),
    REG_JNI(register_android_graphics_Graphics),
    REG_JNI(register_android_view_GraphicBuffer),
    REG_JNI(register_android_view_GLES20DisplayList),
+0 −104
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <assert.h>

#include <ui/PixelFormat.h>

#include "jni.h"
#include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h>
#include <utils/misc.h>

// ----------------------------------------------------------------------------

namespace android {

// ----------------------------------------------------------------------------

struct offsets_t {
    jfieldID bytesPerPixel;
    jfieldID bitsPerPixel;
};

static offsets_t offsets;

// ----------------------------------------------------------------------------

static void android_graphics_getPixelFormatInfo(
        JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject)
{
    PixelFormatInfo info;
    status_t err;

    // we need this for backward compatibility with PixelFormat's
    // deprecated constants
    switch (format) {
    case HAL_PIXEL_FORMAT_YCbCr_422_SP:
        // defined as the bytes per pixel of the Y plane
        info.bytesPerPixel = 1;
        info.bitsPerPixel = 16;
        goto done;
    case HAL_PIXEL_FORMAT_YCrCb_420_SP:
        // defined as the bytes per pixel of the Y plane
        info.bytesPerPixel = 1;
        info.bitsPerPixel = 12;
        goto done;
    case HAL_PIXEL_FORMAT_YCbCr_422_I:
        // defined as the bytes per pixel of the Y plane
        info.bytesPerPixel = 1;
        info.bitsPerPixel = 16;
        goto done;
    }

    err = getPixelFormatInfo(format, &info);
    if (err < 0) {
        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
        return;
    }

done:
    env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel);
    env->SetIntField(pixelFormatObject, offsets.bitsPerPixel,  info.bitsPerPixel);
}
// ----------------------------------------------------------------------------

const char* const kClassPathName = "android/graphics/PixelFormat";

static void nativeClassInit(JNIEnv* env, jclass clazz);

static JNINativeMethod gMethods[] = {
    {   "nativeClassInit", "()V",
        (void*)nativeClassInit },
	{   "getPixelFormatInfo", "(ILandroid/graphics/PixelFormat;)V",
        (void*)android_graphics_getPixelFormatInfo
    }
};

void nativeClassInit(JNIEnv* env, jclass clazz)
{
    offsets.bytesPerPixel = env->GetFieldID(clazz, "bytesPerPixel", "I");
    offsets.bitsPerPixel  = env->GetFieldID(clazz, "bitsPerPixel", "I");
}

int register_android_graphics_PixelFormat(JNIEnv* env)
{
    return AndroidRuntime::registerNativeMethods(env,
            kClassPathName, gMethods, NELEM(gMethods));
}

};
+38 −7
Original line number Diff line number Diff line
@@ -43,7 +43,9 @@ public class PixelFormat
    public static final int RGBA_5551   = 6;
    @Deprecated
    public static final int RGBA_4444   = 7;
    @Deprecated
    public static final int A_8         = 8;
    @Deprecated
    public static final int L_8         = 9;
    @Deprecated
    public static final int LA_88       = 0xA;
@@ -79,14 +81,43 @@ public class PixelFormat
    @Deprecated
    public static final int JPEG        = 0x100;

    /*
     * We use a class initializer to allow the native code to cache some
     * field offsets.
     */
    native private static void nativeClassInit();
    static { nativeClassInit(); }
    public static void getPixelFormatInfo(int format, PixelFormat info) {
        switch (format) {
            case RGBA_8888:
            case RGBX_8888:
                info.bitsPerPixel = 32;
                info.bytesPerPixel = 4;
                break;
            case RGB_888:
                info.bitsPerPixel = 24;
                info.bytesPerPixel = 3;
                break;
            case RGB_565:
            case RGBA_5551:
            case RGBA_4444:
                info.bitsPerPixel = 16;
                info.bytesPerPixel = 2;
                break;
            case A_8:
            case L_8:
            case RGB_332:
                info.bitsPerPixel = 8;
                info.bytesPerPixel = 1;
                break;
            case YCbCr_422_SP:
            case YCbCr_422_I:
                info.bitsPerPixel = 16;
                info.bytesPerPixel = 1;
                break;
            case YCbCr_420_SP:
                info.bitsPerPixel = 12;
                info.bytesPerPixel = 1;
                break;
            default:
                throw new IllegalArgumentException("unkonwon pixel format " + format);
        }
    }

    public static native void getPixelFormatInfo(int format, PixelFormat info);
    public static boolean formatHasAlpha(int format) {
        switch (format) {
            case PixelFormat.A_8: