1/*
2 * Copyright (c) 2002, 2008, 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
26package sun.java2d.windows;
27
28import java.awt.Composite;
29import sun.java2d.loops.GraphicsPrimitive;
30import sun.java2d.loops.GraphicsPrimitiveMgr;
31import sun.java2d.loops.CompositeType;
32import sun.java2d.loops.SurfaceType;
33import sun.java2d.loops.Blit;
34import sun.java2d.pipe.Region;
35import sun.java2d.SurfaceData;
36
37/**
38 * GDIBlitLoops
39 *
40 * This class accelerates Blits between certain surfaces and the
41 * screen, using GDI.  The reason for these loops is to find
42 * a way of copying to the screen without using DDraw locking
43 * that is faster than our current fallback (which creates
44 * a temporary GDI DIB)
45 */
46public class GDIBlitLoops extends Blit {
47
48    // Store these values to be passed to native code
49    int rmask, gmask, bmask;
50
51    // Needs lookup table (for indexed color image copies)
52    boolean indexed = false;
53
54    /**
55     * Note that we do not register loops to 8-byte destinations.  This
56     * is due to faster processing of dithering through our software
57     * loops than through GDI StretchBlt processing.
58     */
59    public static void register()
60    {
61        GraphicsPrimitive[] primitives = {
62            new GDIBlitLoops(SurfaceType.IntRgb,
63                             GDIWindowSurfaceData.AnyGdi),
64            new GDIBlitLoops(SurfaceType.Ushort555Rgb,
65                             GDIWindowSurfaceData.AnyGdi,
66                             0x7C00, 0x03E0, 0x001F),
67            new GDIBlitLoops(SurfaceType.Ushort565Rgb,
68                             GDIWindowSurfaceData.AnyGdi,
69                             0xF800, 0x07E0, 0x001F),
70            new GDIBlitLoops(SurfaceType.ThreeByteBgr,
71                             GDIWindowSurfaceData.AnyGdi),
72            new GDIBlitLoops(SurfaceType.ByteIndexedOpaque,
73                             GDIWindowSurfaceData.AnyGdi,
74                             true),
75            new GDIBlitLoops(SurfaceType.Index8Gray,
76                             GDIWindowSurfaceData.AnyGdi,
77                             true),
78            new GDIBlitLoops(SurfaceType.ByteGray,
79                             GDIWindowSurfaceData.AnyGdi),
80        };
81        GraphicsPrimitiveMgr.register(primitives);
82    }
83
84    /**
85     * This constructor exists for srcTypes that have no need of
86     * component masks. GDI only expects masks for 2- and 4-byte
87     * DIBs, so all 1- and 3-byte srcTypes can skip the mask setting.
88     */
89    public GDIBlitLoops(SurfaceType srcType, SurfaceType dstType) {
90        this(srcType, dstType, 0, 0, 0);
91    }
92
93    /**
94     * This constructor exists for srcTypes that need lookup tables
95     * during image copying.
96     */
97    public GDIBlitLoops(SurfaceType srcType, SurfaceType dstType,
98                        boolean indexed)
99    {
100        this(srcType, dstType, 0, 0, 0);
101        this.indexed = indexed;
102    }
103
104    /**
105     * This constructor sets mask for this primitive which can be
106     * retrieved in native code to set the appropriate values for GDI.
107     */
108    public GDIBlitLoops(SurfaceType srcType, SurfaceType dstType,
109                        int rmask, int gmask, int bmask)
110    {
111        super(srcType, CompositeType.SrcNoEa, dstType);
112        this.rmask = rmask;
113        this.gmask = gmask;
114        this.bmask = bmask;
115    }
116
117    /**
118     * nativeBlit
119     * This native method is where all of the work happens in the
120     * accelerated Blit.
121     */
122    public native void nativeBlit(SurfaceData src, SurfaceData dst,
123                                  Region clip,
124                                  int sx, int sy, int dx, int dy,
125                                  int w, int h,
126                                  int rmask, int gmask, int bmask,
127                                  boolean needLut);
128
129    /**
130     * Blit
131     * This method wraps the nativeBlit call, sending in additional
132     * info on whether the native method needs to get LUT info
133     * from the source image.  Note that we do not pass in the
134     * Composite data because we only register these loops for
135     * SrcNoEa composite operations.
136     */
137    public void Blit(SurfaceData src, SurfaceData dst,
138                     Composite comp, Region clip,
139                     int sx, int sy, int dx, int dy, int w, int h)
140    {
141        nativeBlit(src, dst, clip, sx, sy, dx, dy, w, h,
142                   rmask, gmask, bmask, indexed);
143    }
144
145
146}
147