1 | /* |
2 | * Copyright (c) 2003, 2007, Oracle and/or its affiliates. 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. Oracle designates this |
8 | * particular file as subject to the "Classpath" exception as provided |
9 | * by Oracle 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 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. |
24 | */ |
25 | |
26 | #ifndef HEADLESS |
27 | |
28 | #include <stdlib.h> |
29 | #include <jlong.h> |
30 | |
31 | #include "OGLMaskBlit.h" |
32 | #include "OGLRenderQueue.h" |
33 | #include "OGLSurfaceData.h" |
34 | |
35 | /** |
36 | * REMIND: This method assumes that the dimensions of the incoming pixel |
37 | * array are less than or equal to the cached blit texture tile; |
38 | * these are rather fragile assumptions, and should be cleaned up... |
39 | */ |
40 | void |
41 | OGLMaskBlit_MaskBlit(JNIEnv *env, OGLContext *oglc, |
42 | jint dstx, jint dsty, |
43 | jint width, jint height, |
44 | void *pPixels) |
45 | { |
46 | GLfloat tx1, ty1, tx2, ty2; |
47 | |
48 | J2dTraceLn(J2D_TRACE_INFO, "OGLMaskBlit_MaskBlit" ); |
49 | |
50 | if (width <= 0 || height <= 0) { |
51 | J2dTraceLn(J2D_TRACE_WARNING, |
52 | "OGLMaskBlit_MaskBlit: invalid dimensions" ); |
53 | return; |
54 | } |
55 | |
56 | RETURN_IF_NULL(pPixels); |
57 | RETURN_IF_NULL(oglc); |
58 | CHECK_PREVIOUS_OP(GL_TEXTURE_2D); |
59 | |
60 | if (oglc->blitTextureID == 0) { |
61 | if (!OGLContext_InitBlitTileTexture(oglc)) { |
62 | J2dRlsTraceLn(J2D_TRACE_ERROR, |
63 | "OGLMaskBlit_MaskBlit: could not init blit tile" ); |
64 | return; |
65 | } |
66 | } |
67 | |
68 | // set up texture parameters |
69 | j2d_glBindTexture(GL_TEXTURE_2D, oglc->blitTextureID); |
70 | OGLC_UPDATE_TEXTURE_FUNCTION(oglc, GL_MODULATE); |
71 | j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
72 | j2d_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
73 | |
74 | // copy system memory IntArgbPre surface into cached texture |
75 | j2d_glTexSubImage2D(GL_TEXTURE_2D, 0, |
76 | 0, 0, width, height, |
77 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pPixels); |
78 | |
79 | tx1 = 0.0f; |
80 | ty1 = 0.0f; |
81 | tx2 = ((GLfloat)width) / OGLC_BLIT_TILE_SIZE; |
82 | ty2 = ((GLfloat)height) / OGLC_BLIT_TILE_SIZE; |
83 | |
84 | // render cached texture to the OpenGL surface |
85 | j2d_glBegin(GL_QUADS); |
86 | j2d_glTexCoord2f(tx1, ty1); j2d_glVertex2i(dstx, dsty); |
87 | j2d_glTexCoord2f(tx2, ty1); j2d_glVertex2i(dstx + width, dsty); |
88 | j2d_glTexCoord2f(tx2, ty2); j2d_glVertex2i(dstx + width, dsty + height); |
89 | j2d_glTexCoord2f(tx1, ty2); j2d_glVertex2i(dstx, dsty + height); |
90 | j2d_glEnd(); |
91 | } |
92 | |
93 | #endif /* !HEADLESS */ |
94 | |