Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/sun/awt/image/DataBufferNative.c
38918 views
/*1* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdlib.h>2627#include "SurfaceData.h"28#include "sun_awt_image_DataBufferNative.h"2930#include "jni_util.h"31#include "debug_trace.h"32#include <stdio.h>3334unsigned char *DBN_GetPixelPointer(JNIEnv *env, jint x, int y,35SurfaceDataRasInfo *lockInfo,36SurfaceDataOps *ops, int lockFlag)37{38if (ops == NULL) {39return NULL;40}4142lockInfo->bounds.x1 = x;43lockInfo->bounds.y1 = y;44lockInfo->bounds.x2 = x + 1;45lockInfo->bounds.y2 = y + 1;46if (ops->Lock(env, ops, lockInfo, lockFlag) != SD_SUCCESS) {47return NULL;48}49ops->GetRasInfo(env, ops, lockInfo);50if (lockInfo->rasBase) {51unsigned char *pixelPtr = (52(unsigned char*)lockInfo->rasBase +53(x * lockInfo->pixelStride + y * lockInfo->scanStride));54return pixelPtr;55}56SurfaceData_InvokeRelease(env, ops, lockInfo);57SurfaceData_InvokeUnlock(env, ops, lockInfo);58return NULL;59}6061/*62* Class: sun_awt_image_DataBufferNative63* Method: getElem64* Signature:65*/66JNIEXPORT jint JNICALL67Java_sun_awt_image_DataBufferNative_getElem(JNIEnv *env, jobject dbn,68jint x, jint y, jobject sd)69{70jint returnVal = -1;71unsigned char *pixelPtr;72SurfaceDataRasInfo lockInfo;73SurfaceDataOps *ops;7475ops = SurfaceData_GetOps(env, sd);76JNU_CHECK_EXCEPTION_RETURN(env, -1);7778if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo,79ops, SD_LOCK_READ)))80{81return returnVal;82}83switch (lockInfo.pixelStride) {84case 4:85returnVal = *(int *)pixelPtr;86break;87/* REMIND: do we need a 3-byte case (for 24-bit) here? */88case 2:89returnVal = *(unsigned short *)pixelPtr;90break;91case 1:92returnVal = *pixelPtr;93break;94default:95break;96}97SurfaceData_InvokeRelease(env, ops, &lockInfo);98SurfaceData_InvokeUnlock(env, ops, &lockInfo);99return returnVal;100}101102103/*104* Class: sun_awt_image_DataBufferNative105* Method: setElem106* Signature:107*/108JNIEXPORT void JNICALL109Java_sun_awt_image_DataBufferNative_setElem(JNIEnv *env, jobject dbn,110jint x, jint y, jint val, jobject sd)111{112SurfaceDataRasInfo lockInfo;113SurfaceDataOps *ops;114unsigned char *pixelPtr;115116117ops = SurfaceData_GetOps(env, sd);118JNU_CHECK_EXCEPTION(env);119120if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo,121ops, SD_LOCK_WRITE)))122{123return;124}125126switch (lockInfo.pixelStride) {127case 4:128*(int *)pixelPtr = val;129break;130/* REMIND: do we need a 3-byte case (for 24-bit) here? */131case 2:132*(unsigned short *)pixelPtr = (unsigned short)val;133break;134case 1:135*pixelPtr = (unsigned char)val;136break;137default:138break;139}140SurfaceData_InvokeRelease(env, ops, &lockInfo);141SurfaceData_InvokeUnlock(env, ops, &lockInfo);142}143144145