Jogamp
Bug 741 HiDPI: Simplify ScalableSurface (2): Add request pixelScale API entry, fixed...
[jogl.git] / src / nativewindow / classes / jogamp / nativewindow / WrappedSurface.java
CommitLineData
bb3d3743
SG
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
4dd44b98 29package jogamp.nativewindow;
bb3d3743
SG
30
31import javax.media.nativewindow.AbstractGraphicsConfiguration;
4dd44b98 32import javax.media.nativewindow.AbstractGraphicsDevice;
bb3d3743 33import javax.media.nativewindow.ProxySurface;
2571ed0b 34import javax.media.nativewindow.ScalableSurface;
4dd44b98 35import javax.media.nativewindow.UpstreamSurfaceHook;
bb3d3743 36
4dd44b98 37import com.jogamp.nativewindow.UpstreamSurfaceHookMutableSize;
bb3d3743 38
6c823db5
SG
39/**
40 * Generic Surface implementation which wraps an existing window handle.
5e9c02bc 41 *
6c823db5
SG
42 * @see ProxySurface
43 */
2571ed0b
SG
44public class WrappedSurface extends ProxySurfaceImpl implements ScalableSurface {
45 private final int[] hasPixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
46 private long surfaceHandle;
4dd44b98
SG
47
48 /**
49 * Utilizes a {@link UpstreamSurfaceHook.MutableSize} to hold the size information,
50 * which is being passed to the {@link ProxySurface} instance.
5e9c02bc 51 *
4dd44b98
SG
52 * @param cfg the {@link AbstractGraphicsConfiguration} to be used
53 * @param handle the wrapped pre-existing native surface handle, maybe 0 if not yet determined
54 * @param initialWidth
55 * @param initialHeight
56 * @param ownsDevice <code>true</code> if this {@link ProxySurface} instance
57 * owns the {@link AbstractGraphicsConfiguration}'s {@link AbstractGraphicsDevice},
58 * otherwise <code>false</code>. Owning the device implies closing it at {@link #destroyNotify()}.
59 */
60 public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle, int initialWidth, int initialHeight, boolean ownsDevice) {
61 super(cfg, new UpstreamSurfaceHookMutableSize(initialWidth, initialHeight), ownsDevice);
62 surfaceHandle=handle;
63 }
5e9c02bc 64
4dd44b98
SG
65 /**
66 * @param cfg the {@link AbstractGraphicsConfiguration} to be used
67 * @param handle the wrapped pre-existing native surface handle, maybe 0 if not yet determined
68 * @param upstream the {@link UpstreamSurfaceHook} to be used
69 * @param ownsDevice <code>true</code> if this {@link ProxySurface} instance
70 * owns the {@link AbstractGraphicsConfiguration}'s {@link AbstractGraphicsDevice},
71 * otherwise <code>false</code>.
72 */
73 public WrappedSurface(AbstractGraphicsConfiguration cfg, long handle, UpstreamSurfaceHook upstream, boolean ownsDevice) {
74 super(cfg, upstream, ownsDevice);
75 surfaceHandle=handle;
bb3d3743 76 }
6bff4302
SG
77
78 @Override
5e9c02bc 79 protected void invalidateImpl() {
bb3d3743 80 surfaceHandle = 0;
2571ed0b
SG
81 hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
82 hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
bb3d3743
SG
83 }
84
6bff4302 85 @Override
20bf031d 86 public final long getSurfaceHandle() {
bb3d3743
SG
87 return surfaceHandle;
88 }
89
6bff4302 90 @Override
20bf031d 91 public final void setSurfaceHandle(long surfaceHandle) {
bb3d3743
SG
92 this.surfaceHandle=surfaceHandle;
93 }
5e9c02bc 94
6bff4302 95 @Override
20bf031d
SG
96 protected final int lockSurfaceImpl() {
97 return LOCK_SUCCESS;
bb3d3743
SG
98 }
99
6bff4302 100 @Override
20bf031d 101 protected final void unlockSurfaceImpl() {
bb3d3743
SG
102 }
103
2571ed0b
SG
104 /**
105 * {@inheritDoc}
106 * <p>
58153310 107 * {@link WrappedSurface}'s implementation uses the {@link #setSurfaceScale(int[]) given pixelScale} directly.
2571ed0b
SG
108 * </p>
109 */
f9a00b91 110 @Override
fb57c652 111 public final int[] convertToWindowUnits(final int[] pixelUnitsAndResult) {
2571ed0b
SG
112 pixelUnitsAndResult[0] /= hasPixelScale[0];
113 pixelUnitsAndResult[1] /= hasPixelScale[1];
114 return pixelUnitsAndResult;
f9a00b91
SG
115 }
116
2571ed0b
SG
117 /**
118 * {@inheritDoc}
119 * <p>
58153310 120 * {@link WrappedSurface}'s implementation uses the {@link #setSurfaceScale(int[]) given pixelScale} directly.
2571ed0b
SG
121 * </p>
122 */
f9a00b91 123 @Override
fb57c652 124 public final int[] convertToPixelUnits(final int[] windowUnitsAndResult) {
2571ed0b
SG
125 windowUnitsAndResult[0] *= hasPixelScale[0];
126 windowUnitsAndResult[1] *= hasPixelScale[1];
127 return windowUnitsAndResult;
128 }
129
130 /**
131 * {@inheritDoc}
132 * <p>
133 * {@link WrappedSurface}'s implementation is to simply pass the given pixelScale
134 * from the caller <i>down</i> to this instance without validation to be applied in the {@link #convertToPixelUnits(int[]) conversion} {@link #convertToWindowUnits(int[]) methods} <b>only</b>.<br/>
135 * This allows the caller to pass down knowledge about window- and pixel-unit conversion and utilize mentioned conversion methods.
136 * </p>
137 * <p>
138 * The given pixelScale will not impact the actual {@link #getSurfaceWidth()} and {@link #getSurfaceHeight()},
139 * which is determinated by this instances {@link #getUpstreamSurface() upstream surface}.
140 * </p>
141 * <p>
142 * Implementation uses the default pixelScale {@link ScalableSurface#IDENTITY_PIXELSCALE}
143 * and resets to default values on {@link #invalidateImpl()}, i.e. {@link #destroyNotify()}.
144 * </p>
145 * <p>
146 * Implementation returns the given pixelScale array.
147 * </p>
148 */
149 @Override
58153310 150 public final void setSurfaceScale(final int[] pixelScale) {
2571ed0b
SG
151 hasPixelScale[0] = pixelScale[0];
152 hasPixelScale[1] = pixelScale[1];
58153310
SG
153 }
154
155 @Override
156 public final int[] getRequestedSurfaceScale(final int[] result) {
157 System.arraycopy(hasPixelScale, 0, result, 0, 2);
3fb76fce 158 return result;
2571ed0b
SG
159 }
160
161 @Override
58153310 162 public final int[] getCurrentSurfaceScale(final int[] result) {
2571ed0b
SG
163 System.arraycopy(hasPixelScale, 0, result, 0, 2);
164 return result;
f9a00b91
SG
165 }
166
fb57c652 167}
http://JogAmp.org git info: FAQ, tutorial and man pages.