1 /*
2 * Copyright (c) 2005, 2006, 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
184 * the lower-left corner of the viewport region, relative to the
185 * lower-left corner of the given surface.
186 *
187 * @param g the Graphics object for the corresponding destination surface;
188 * cannot be null
189 * @param componentWidth width of the component to be painted
190 * @param componentHeight height of the component to be painted
191 * @return a Rectangle describing the OpenGL viewport for the given
192 * destination surface and component dimensions, or null if the given
193 * Graphics object is invalid
194 */
195 public static Rectangle getOGLViewport(Graphics g,
196 int componentWidth,
197 int componentHeight)
198 {
199 if (!(g instanceof SunGraphics2D)) {
200 return null;
201 }
202
203 SunGraphics2D sg2d = (SunGraphics2D)g;
204 SurfaceData sData = (SurfaceData)sg2d.surfaceData;
205
206 // this is the upper-left origin of the region to be painted,
207 // relative to the upper-left origin of the surface
208 // (in Java2D coordinates)
209 int x0 = sg2d.transX;
210 int y0 = sg2d.transY;
211
212 // this is the lower-left origin of the region to be painted,
213 // relative to the lower-left origin of the surface
214 // (in OpenGL coordinates)
215 Rectangle surfaceBounds = sData.getBounds();
216 int x1 = x0;
217 int y1 = surfaceBounds.height - (y0 + componentHeight);
218
219 return new Rectangle(x1, y1, componentWidth, componentHeight);
220 }
221
222 /**
223 * Returns the Rectangle describing the OpenGL scissor box on the
224 * Java 2D surface associated with the given Graphics object. When a
225 * third-party library is performing OpenGL rendering directly
226 * into the visible region of the associated surface, this scissor box
227 * must be set to avoid drawing over existing rendering results.
228 *
229 * Note that the x/y values in the returned Rectangle object represent
230 * the lower-left corner of the scissor region, relative to the
231 * lower-left corner of the given surface.
232 *
233 * @param g the Graphics object for the corresponding destination surface;
234 * cannot be null
235 * @return a Rectangle describing the OpenGL scissor box for the given
236 * Graphics object and corresponding destination surface, or null if the
237 * given Graphics object is invalid or the clip region is non-rectangular
238 */
239 public static Rectangle getOGLScissorBox(Graphics g) {
240 if (!(g instanceof SunGraphics2D)) {
241 return null;
242 }
243
244 SunGraphics2D sg2d = (SunGraphics2D)g;
245 SurfaceData sData = (SurfaceData)sg2d.surfaceData;
246 Region r = sg2d.getCompClip();
247 if (!r.isRectangular()) {
248 // caller probably doesn't know how to handle shape clip
249 // appropriately, so just return null (Swing currently never
250 // sets a shape clip, but that could change in the future)
251 return null;
252 }
253
254 // this is the upper-left origin of the scissor box relative to the
255 // upper-left origin of the surface (in Java 2D coordinates)
256 int x0 = r.getLoX();
257 int y0 = r.getLoY();
258
259 // this is the width and height of the scissor region
260 int w = r.getWidth();
261 int h = r.getHeight();
262
263 // this is the lower-left origin of the scissor box relative to the
264 // lower-left origin of the surface (in OpenGL coordinates)
265 Rectangle surfaceBounds = sData.getBounds();
|
1 /*
2 * Copyright (c) 2005, 2014, 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
184 * the lower-left corner of the viewport region, relative to the
185 * lower-left corner of the given surface.
186 *
187 * @param g the Graphics object for the corresponding destination surface;
188 * cannot be null
189 * @param componentWidth width of the component to be painted
190 * @param componentHeight height of the component to be painted
191 * @return a Rectangle describing the OpenGL viewport for the given
192 * destination surface and component dimensions, or null if the given
193 * Graphics object is invalid
194 */
195 public static Rectangle getOGLViewport(Graphics g,
196 int componentWidth,
197 int componentHeight)
198 {
199 if (!(g instanceof SunGraphics2D)) {
200 return null;
201 }
202
203 SunGraphics2D sg2d = (SunGraphics2D)g;
204 SurfaceData sData = sg2d.surfaceData;
205
206 // this is the upper-left origin of the region to be painted,
207 // relative to the upper-left origin of the surface
208 // (in Java2D coordinates)
209 int x0 = sg2d.transX;
210 int y0 = sg2d.transY;
211
212 // this is the lower-left origin of the region to be painted,
213 // relative to the lower-left origin of the surface
214 // (in OpenGL coordinates)
215 Rectangle surfaceBounds = sData.getBounds();
216 int x1 = x0;
217 int y1 = surfaceBounds.height - (y0 + componentHeight);
218
219 return new Rectangle(x1, y1, componentWidth, componentHeight);
220 }
221
222 /**
223 * Returns the Rectangle describing the OpenGL scissor box on the
224 * Java 2D surface associated with the given Graphics object. When a
225 * third-party library is performing OpenGL rendering directly
226 * into the visible region of the associated surface, this scissor box
227 * must be set to avoid drawing over existing rendering results.
228 *
229 * Note that the x/y values in the returned Rectangle object represent
230 * the lower-left corner of the scissor region, relative to the
231 * lower-left corner of the given surface.
232 *
233 * @param g the Graphics object for the corresponding destination surface;
234 * cannot be null
235 * @return a Rectangle describing the OpenGL scissor box for the given
236 * Graphics object and corresponding destination surface, or null if the
237 * given Graphics object is invalid or the clip region is non-rectangular
238 */
239 public static Rectangle getOGLScissorBox(Graphics g) {
240 if (!(g instanceof SunGraphics2D)) {
241 return null;
242 }
243
244 SunGraphics2D sg2d = (SunGraphics2D)g;
245 SurfaceData sData = sg2d.surfaceData;
246 Region r = sg2d.getCompClip();
247 if (!r.isRectangular()) {
248 // caller probably doesn't know how to handle shape clip
249 // appropriately, so just return null (Swing currently never
250 // sets a shape clip, but that could change in the future)
251 return null;
252 }
253
254 // this is the upper-left origin of the scissor box relative to the
255 // upper-left origin of the surface (in Java 2D coordinates)
256 int x0 = r.getLoX();
257 int y0 = r.getLoY();
258
259 // this is the width and height of the scissor region
260 int w = r.getWidth();
261 int h = r.getHeight();
262
263 // this is the lower-left origin of the scissor box relative to the
264 // lower-left origin of the surface (in OpenGL coordinates)
265 Rectangle surfaceBounds = sData.getBounds();
|