author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
42455 | 2 |
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
26 |
#include <stdlib.h> |
2 | 27 |
|
28 |
#include "SurfaceData.h" |
|
29 |
#include "sun_awt_image_DataBufferNative.h" |
|
30 |
||
31 |
#include "jni_util.h" |
|
32 |
#include "debug_trace.h" |
|
33 |
#include <stdio.h> |
|
34 |
||
35 |
unsigned char *DBN_GetPixelPointer(JNIEnv *env, jint x, int y, |
|
36 |
SurfaceDataRasInfo *lockInfo, |
|
37 |
SurfaceDataOps *ops, int lockFlag) |
|
38 |
{ |
|
39 |
if (ops == NULL) { |
|
40 |
return NULL; |
|
41 |
} |
|
42 |
||
43 |
lockInfo->bounds.x1 = x; |
|
44 |
lockInfo->bounds.y1 = y; |
|
45 |
lockInfo->bounds.x2 = x + 1; |
|
46 |
lockInfo->bounds.y2 = y + 1; |
|
47 |
if (ops->Lock(env, ops, lockInfo, lockFlag) != SD_SUCCESS) { |
|
48 |
return NULL; |
|
49 |
} |
|
50 |
ops->GetRasInfo(env, ops, lockInfo); |
|
51 |
if (lockInfo->rasBase) { |
|
52 |
unsigned char *pixelPtr = ( |
|
53 |
(unsigned char*)lockInfo->rasBase + |
|
54 |
(x * lockInfo->pixelStride + y * lockInfo->scanStride)); |
|
55 |
return pixelPtr; |
|
56 |
} |
|
57 |
SurfaceData_InvokeRelease(env, ops, lockInfo); |
|
58 |
SurfaceData_InvokeUnlock(env, ops, lockInfo); |
|
59 |
return NULL; |
|
60 |
} |
|
61 |
||
62 |
/* |
|
63 |
* Class: sun_awt_image_DataBufferNative |
|
64 |
* Method: getElem |
|
65 |
* Signature: |
|
66 |
*/ |
|
67 |
JNIEXPORT jint JNICALL |
|
68 |
Java_sun_awt_image_DataBufferNative_getElem(JNIEnv *env, jobject dbn, |
|
69 |
jint x, jint y, jobject sd) |
|
70 |
{ |
|
71 |
jint returnVal = -1; |
|
72 |
unsigned char *pixelPtr; |
|
73 |
SurfaceDataRasInfo lockInfo; |
|
74 |
SurfaceDataOps *ops; |
|
42455 | 75 |
lockInfo.rasBase = NULL; |
2 | 76 |
|
77 |
ops = SurfaceData_GetOps(env, sd); |
|
23644
0cdb97daeef5
8030787: [Parfait] JNI-related warnings from b119 for jdk/src/share/native/sun/awt/image
pchelko
parents:
23010
diff
changeset
|
78 |
JNU_CHECK_EXCEPTION_RETURN(env, -1); |
2 | 79 |
|
80 |
if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo, |
|
81 |
ops, SD_LOCK_READ))) |
|
82 |
{ |
|
83 |
return returnVal; |
|
84 |
} |
|
85 |
switch (lockInfo.pixelStride) { |
|
86 |
case 4: |
|
87 |
returnVal = *(int *)pixelPtr; |
|
88 |
break; |
|
89 |
/* REMIND: do we need a 3-byte case (for 24-bit) here? */ |
|
90 |
case 2: |
|
91 |
returnVal = *(unsigned short *)pixelPtr; |
|
92 |
break; |
|
93 |
case 1: |
|
94 |
returnVal = *pixelPtr; |
|
95 |
break; |
|
96 |
default: |
|
97 |
break; |
|
98 |
} |
|
99 |
SurfaceData_InvokeRelease(env, ops, &lockInfo); |
|
100 |
SurfaceData_InvokeUnlock(env, ops, &lockInfo); |
|
101 |
return returnVal; |
|
102 |
} |
|
103 |
||
104 |
||
105 |
/* |
|
106 |
* Class: sun_awt_image_DataBufferNative |
|
107 |
* Method: setElem |
|
108 |
* Signature: |
|
109 |
*/ |
|
110 |
JNIEXPORT void JNICALL |
|
111 |
Java_sun_awt_image_DataBufferNative_setElem(JNIEnv *env, jobject dbn, |
|
112 |
jint x, jint y, jint val, jobject sd) |
|
113 |
{ |
|
114 |
SurfaceDataRasInfo lockInfo; |
|
115 |
SurfaceDataOps *ops; |
|
116 |
unsigned char *pixelPtr; |
|
42455 | 117 |
lockInfo.rasBase = NULL; |
2 | 118 |
|
119 |
ops = SurfaceData_GetOps(env, sd); |
|
23644
0cdb97daeef5
8030787: [Parfait] JNI-related warnings from b119 for jdk/src/share/native/sun/awt/image
pchelko
parents:
23010
diff
changeset
|
120 |
JNU_CHECK_EXCEPTION(env); |
2 | 121 |
|
122 |
if (!(pixelPtr = DBN_GetPixelPointer(env, x, y, &lockInfo, |
|
123 |
ops, SD_LOCK_WRITE))) |
|
124 |
{ |
|
125 |
return; |
|
126 |
} |
|
127 |
||
128 |
switch (lockInfo.pixelStride) { |
|
129 |
case 4: |
|
130 |
*(int *)pixelPtr = val; |
|
131 |
break; |
|
132 |
/* REMIND: do we need a 3-byte case (for 24-bit) here? */ |
|
133 |
case 2: |
|
134 |
*(unsigned short *)pixelPtr = (unsigned short)val; |
|
135 |
break; |
|
136 |
case 1: |
|
137 |
*pixelPtr = (unsigned char)val; |
|
138 |
break; |
|
139 |
default: |
|
140 |
break; |
|
141 |
} |
|
142 |
SurfaceData_InvokeRelease(env, ops, &lockInfo); |
|
143 |
SurfaceData_InvokeUnlock(env, ops, &lockInfo); |
|
144 |
} |