blob: 28f5ea0335be1e2b5c36fa90c1d1f3205675a3bd [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
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 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26#include "GraphicsPrimitiveMgr.h"
27#include "Region.h"
28
29#include "sun_java2d_loops_Blit.h"
30
31/*
32 * Class: sun_java2d_loops_Blit
33 * Method: Blit
34 * Signature: (Lsun/java2d/SurfaceData;Lsun/java2d/SurfaceData;Ljava/awt/Composite;IIIIII)V
35 */
36JNIEXPORT void JNICALL
37Java_sun_java2d_loops_Blit_Blit
38 (JNIEnv *env, jobject self,
39 jobject srcData, jobject dstData, jobject comp, jobject clip,
40 jint srcx, jint srcy, jint dstx, jint dsty, jint width, jint height)
41{
42 SurfaceDataOps *srcOps;
43 SurfaceDataOps *dstOps;
44 SurfaceDataRasInfo srcInfo;
45 SurfaceDataRasInfo dstInfo;
46 NativePrimitive *pPrim;
47 CompositeInfo compInfo;
48 RegionData clipInfo;
49 jint dstFlags;
50
51 pPrim = GetNativePrim(env, self);
52 if (pPrim == NULL) {
53 return;
54 }
55 if (pPrim->pCompType->getCompInfo != NULL) {
56 (*pPrim->pCompType->getCompInfo)(env, &compInfo, comp);
57 }
58 if (Region_GetInfo(env, clip, &clipInfo)) {
59 return;
60 }
61
62 srcOps = SurfaceData_GetOps(env, srcData);
63 dstOps = SurfaceData_GetOps(env, dstData);
64 if (srcOps == 0 || dstOps == 0) {
65 return;
66 }
67
68 srcInfo.bounds.x1 = srcx;
69 srcInfo.bounds.y1 = srcy;
70 srcInfo.bounds.x2 = srcx + width;
71 srcInfo.bounds.y2 = srcy + height;
72 dstInfo.bounds.x1 = dstx;
73 dstInfo.bounds.y1 = dsty;
74 dstInfo.bounds.x2 = dstx + width;
75 dstInfo.bounds.y2 = dsty + height;
76 srcx -= dstx;
77 srcy -= dsty;
78 SurfaceData_IntersectBounds(&dstInfo.bounds, &clipInfo.bounds);
79 if (srcOps->Lock(env, srcOps, &srcInfo, pPrim->srcflags) != SD_SUCCESS) {
80 return;
81 }
82
83 dstFlags = pPrim->dstflags;
84 if (!Region_IsRectangular(&clipInfo)) {
85 dstFlags |= SD_LOCK_PARTIAL_WRITE;
86 }
87 if (dstOps->Lock(env, dstOps, &dstInfo, dstFlags) != SD_SUCCESS) {
88 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
89 return;
90 }
91 SurfaceData_IntersectBlitBounds(&dstInfo.bounds, &srcInfo.bounds,
92 srcx, srcy);
93 Region_IntersectBounds(&clipInfo, &dstInfo.bounds);
94
95 if (!Region_IsEmpty(&clipInfo)) {
96 srcOps->GetRasInfo(env, srcOps, &srcInfo);
97 dstOps->GetRasInfo(env, dstOps, &dstInfo);
98 if (srcInfo.rasBase && dstInfo.rasBase) {
99 SurfaceDataBounds span;
100 jint savesx = srcInfo.bounds.x1;
101 jint savedx = dstInfo.bounds.x1;
102 Region_StartIteration(env, &clipInfo);
103 while (Region_NextIteration(&clipInfo, &span)) {
104 void *pSrc = PtrCoord(srcInfo.rasBase,
105 srcx + span.x1, srcInfo.pixelStride,
106 srcy + span.y1, srcInfo.scanStride);
107 void *pDst = PtrCoord(dstInfo.rasBase,
108 span.x1, dstInfo.pixelStride,
109 span.y1, dstInfo.scanStride);
110 /*
111 * Fix for 4804375
112 * REMIND: There should probably be a better
113 * way to give the span coordinates to the
114 * inner loop. This is only really needed
115 * for the 1, 2, and 4 bit loops.
116 */
117 srcInfo.bounds.x1 = srcx + span.x1;
118 dstInfo.bounds.x1 = span.x1;
119 (*pPrim->funcs.blit)(pSrc, pDst,
120 span.x2 - span.x1, span.y2 - span.y1,
121 &srcInfo, &dstInfo, pPrim, &compInfo);
122 }
123 Region_EndIteration(env, &clipInfo);
124 srcInfo.bounds.x1 = savesx;
125 dstInfo.bounds.x1 = savedx;
126 }
127 SurfaceData_InvokeRelease(env, dstOps, &dstInfo);
128 SurfaceData_InvokeRelease(env, srcOps, &srcInfo);
129 }
130 SurfaceData_InvokeUnlock(env, dstOps, &dstInfo);
131 SurfaceData_InvokeUnlock(env, srcOps, &srcInfo);
132}