author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 8359 | b2e3eb2cc841 |
child 18232 | b538b71fb429 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8359
diff
changeset
|
2 |
* Copyright (c) 2002, 2011, 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 |
||
1954 | 26 |
#include "awt.h" |
2 | 27 |
#include <sun_java2d_windows_GDIBlitLoops.h> |
28 |
#include "gdefs.h" |
|
29 |
#include "Trace.h" |
|
887 | 30 |
#include "GDIWindowSurfaceData.h" |
2 | 31 |
|
32 |
static RGBQUAD *byteGrayPalette = NULL; |
|
33 |
||
34 |
extern "C" { |
|
35 |
||
36 |
typedef struct tagBitmapheader { |
|
37 |
BITMAPINFOHEADER bmiHeader; |
|
38 |
union { |
|
39 |
DWORD dwMasks[3]; |
|
40 |
RGBQUAD palette[256]; |
|
41 |
} colors; |
|
42 |
} BmiType; |
|
43 |
||
44 |
/* |
|
45 |
* Class: sun_java2d_windows_GDIBlitLoops |
|
46 |
* Method: nativeBlit |
|
47 |
* Signature: (Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;IIIIIIZ)V |
|
48 |
*/ |
|
49 |
JNIEXPORT void JNICALL |
|
50 |
Java_sun_java2d_windows_GDIBlitLoops_nativeBlit |
|
51 |
(JNIEnv *env, jobject joSelf, |
|
52 |
jobject srcData, jobject dstData, |
|
53 |
jobject clip, |
|
54 |
jint srcx, jint srcy, |
|
55 |
jint dstx, jint dsty, |
|
56 |
jint width, jint height, |
|
57 |
jint rmask, jint gmask, jint bmask, |
|
58 |
jboolean needLut) |
|
59 |
{ |
|
60 |
J2dTraceLn(J2D_TRACE_INFO, "GDIBlitLoops_nativeBlit"); |
|
61 |
||
62 |
SurfaceDataRasInfo srcInfo; |
|
63 |
SurfaceDataOps *srcOps = SurfaceData_GetOps(env, srcData); |
|
887 | 64 |
GDIWinSDOps *dstOps = GDIWindowSurfaceData_GetOps(env, dstData); |
2 | 65 |
jint lockFlags; |
66 |
||
67 |
srcInfo.bounds.x1 = srcx; |
|
68 |
srcInfo.bounds.y1 = srcy; |
|
69 |
srcInfo.bounds.x2 = srcx + width; |
|
70 |
srcInfo.bounds.y2 = srcy + height; |
|
71 |
if (needLut) { |
|
72 |
lockFlags = (SD_LOCK_READ | SD_LOCK_LUT); |
|
73 |
} else { |
|
74 |
lockFlags = SD_LOCK_READ; |
|
75 |
} |
|
76 |
// This method is used among other things for on-screen copyArea, in which |
|
77 |
// case the source and destination surfaces are the same. It is important |
|
78 |
// to first lock the source and then get the hDC for the destination |
|
79 |
// surface because the same per-thread hDC will be used for both |
|
80 |
// and we need to have the correct clip set to the hDC |
|
81 |
// used with the SetDIBitsToDevice call. |
|
82 |
if (srcOps->Lock(env, srcOps, &srcInfo, lockFlags) != SD_SUCCESS) { |
|
83 |
return; |
|
84 |
} |
|
85 |
||
86 |
SurfaceDataBounds dstBounds = {dstx, dsty, dstx + width, dsty + height}; |
|
87 |
// Intersect the source and dest rects. Note that the source blit bounds |
|
88 |
// will be adjusted to the surfaces's bounds if needed. |
|
89 |
SurfaceData_IntersectBlitBounds(&(srcInfo.bounds), &dstBounds, |
|
90 |
dstx - srcx, dsty - srcy); |
|
91 |
||
92 |
srcx = srcInfo.bounds.x1; |
|
93 |
srcy = srcInfo.bounds.y1; |
|
94 |
dstx = dstBounds.x1; |
|
95 |
dsty = dstBounds.y1; |
|
96 |
width = srcInfo.bounds.x2 - srcInfo.bounds.x1; |
|
97 |
height = srcInfo.bounds.y2 - srcInfo.bounds.y1; |
|
98 |
||
99 |
if (width > 0 && height > 0) |
|
100 |
{ |
|
101 |
BmiType bmi; |
|
102 |
// REMIND: A performance tweak here would be to make some of this |
|
103 |
// data static. For example, we could have one structure that is |
|
104 |
// always used for ByteGray copies and we only change dynamic data |
|
105 |
// in the structure with every new copy. Also, we could store |
|
106 |
// structures with Ops or with the Java objects so that surfaces |
|
107 |
// could retain their own DIB info and we would not need to |
|
108 |
// recreate it every time. |
|
109 |
||
8359
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
110 |
// GetRasInfo implicitly calls GetPrimitiveArrayCritical |
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
111 |
// and since GetDC uses JNI it needs to be called first. |
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
112 |
HDC hDC = dstOps->GetDC(env, dstOps, 0, NULL, clip, NULL, 0); |
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
113 |
if (hDC == NULL) { |
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
114 |
SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); |
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
115 |
return; |
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
116 |
} |
2 | 117 |
srcOps->GetRasInfo(env, srcOps, &srcInfo); |
118 |
if (srcInfo.rasBase == NULL) { |
|
8359
b2e3eb2cc841
6857592: Getting warning while moving or resizing the frame when component.printAll() is called on local JNI
prr
parents:
5506
diff
changeset
|
119 |
dstOps->ReleaseDC(env, dstOps, hDC); |
2 | 120 |
SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); |
121 |
return; |
|
122 |
} |
|
123 |
void *rasBase = ((char *)srcInfo.rasBase) + srcInfo.scanStride * srcy + |
|
124 |
srcInfo.pixelStride * srcx; |
|
125 |
||
126 |
// If scanlines are DWORD-aligned (scanStride is a multiple of 4), |
|
127 |
// then we can do the work much faster. This is due to a constraint |
|
128 |
// in the way DIBs are structured and parsed by GDI |
|
129 |
jboolean fastBlt = ((srcInfo.scanStride & 0x03) == 0); |
|
130 |
||
131 |
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); |
|
132 |
bmi.bmiHeader.biWidth = srcInfo.scanStride/srcInfo.pixelStride; |
|
133 |
// fastBlt copies whole image in one call; else copy line-by-line |
|
134 |
LONG dwHeight = srcInfo.bounds.y2 - srcInfo.bounds.y1; |
|
135 |
bmi.bmiHeader.biHeight = (fastBlt) ? -dwHeight : -1; |
|
136 |
bmi.bmiHeader.biPlanes = 1; |
|
137 |
bmi.bmiHeader.biBitCount = (WORD)srcInfo.pixelStride * 8; |
|
138 |
// 1,3,4 byte use BI_RGB, 2 byte use BI_BITFIELD... |
|
139 |
// 4 byte _can_ use BI_BITFIELD, but this seems to cause a performance |
|
140 |
// penalty. Since we only ever have one format (xrgb) for 32-bit |
|
141 |
// images that enter this function, just use BI_RGB. |
|
142 |
// Could do BI_RGB for 2-byte 555 format, but no perceived |
|
143 |
// performance benefit. |
|
144 |
bmi.bmiHeader.biCompression = (srcInfo.pixelStride != 2) |
|
145 |
? BI_RGB : BI_BITFIELDS; |
|
146 |
bmi.bmiHeader.biSizeImage = (bmi.bmiHeader.biWidth * dwHeight * |
|
147 |
srcInfo.pixelStride); |
|
148 |
bmi.bmiHeader.biXPelsPerMeter = 0; |
|
149 |
bmi.bmiHeader.biYPelsPerMeter = 0; |
|
150 |
bmi.bmiHeader.biClrUsed = 0; |
|
151 |
bmi.bmiHeader.biClrImportant = 0; |
|
152 |
if (srcInfo.pixelStride == 1) { |
|
153 |
// Copy palette info into bitmap for 8-bit image |
|
154 |
if (needLut) { |
|
155 |
memcpy(bmi.colors.palette, srcInfo.lutBase, srcInfo.lutSize * sizeof(RGBQUAD)); |
|
156 |
if (srcInfo.lutSize != 256) { |
|
157 |
bmi.bmiHeader.biClrUsed = srcInfo.lutSize; |
|
158 |
} |
|
159 |
} else { |
|
160 |
// If no LUT needed, must be ByteGray src. If we have not |
|
161 |
// yet created the byteGrayPalette, create it now and copy |
|
162 |
// it into our temporary bmi structure. |
|
163 |
// REMIND: byteGrayPalette is a leak since we do not have |
|
164 |
// a mechansim to free it up. This should be fine, since it |
|
165 |
// is only 256 bytes for any process and only gets malloc'd |
|
166 |
// when using ByteGray surfaces. Eventually, we should use |
|
167 |
// the new Disposer mechanism to delete this native memory. |
|
168 |
if (byteGrayPalette == NULL) { |
|
169 |
byteGrayPalette = (RGBQUAD *)safe_Malloc(256 * sizeof(RGBQUAD)); |
|
170 |
for (int i = 0; i < 256; ++i) { |
|
171 |
byteGrayPalette[i].rgbRed = i; |
|
172 |
byteGrayPalette[i].rgbGreen = i; |
|
173 |
byteGrayPalette[i].rgbBlue = i; |
|
174 |
} |
|
175 |
} |
|
176 |
memcpy(bmi.colors.palette, byteGrayPalette, 256 * sizeof(RGBQUAD)); |
|
177 |
} |
|
178 |
} else if (srcInfo.pixelStride == 2) { |
|
179 |
// For 16-bit case, init the masks for the pixel depth |
|
180 |
bmi.colors.dwMasks[0] = rmask; |
|
181 |
bmi.colors.dwMasks[1] = gmask; |
|
182 |
bmi.colors.dwMasks[2] = bmask; |
|
183 |
} |
|
184 |
||
185 |
if (fastBlt) { |
|
186 |
// Window could go away at any time, leaving bits on the screen |
|
187 |
// from this GDI call, so make sure window still exists |
|
188 |
if (::IsWindowVisible(dstOps->window)) { |
|
189 |
// Could also call StretchDIBits. Testing showed slight |
|
190 |
// performance advantage of SetDIBits instead, so since we |
|
191 |
// have no need of scaling, might as well use SetDIBits. |
|
192 |
SetDIBitsToDevice(hDC, dstx, dsty, width, height, |
|
193 |
0, 0, 0, height, rasBase, |
|
194 |
(BITMAPINFO*)&bmi, DIB_RGB_COLORS); |
|
195 |
} |
|
196 |
} else { |
|
197 |
// Source scanlines not DWORD-aligned - copy each scanline individually |
|
198 |
for (int i = 0; i < height; i += 1) { |
|
199 |
if (::IsWindowVisible(dstOps->window)) { |
|
200 |
SetDIBitsToDevice(hDC, dstx, dsty+i, width, 1, |
|
201 |
0, 0, 0, 1, rasBase, |
|
202 |
(BITMAPINFO*)&bmi, DIB_RGB_COLORS); |
|
203 |
rasBase = (void*)((char*)rasBase + srcInfo.scanStride); |
|
204 |
} else { |
|
205 |
break; |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
dstOps->ReleaseDC(env, dstOps, hDC); |
|
210 |
SurfaceData_InvokeRelease(env, srcOps, &srcInfo); |
|
211 |
} |
|
212 |
SurfaceData_InvokeUnlock(env, srcOps, &srcInfo); |
|
213 |
||
214 |
return; |
|
215 |
} |
|
216 |
||
217 |
} // extern "C" |