55 import sun.java2d.SurfaceData;
56 import sun.java2d.SurfaceDataProxy;
57 import sun.java2d.loops.SurfaceType;
58 import sun.java2d.loops.CompositeType;
59 import sun.java2d.loops.RenderLoops;
60 import sun.java2d.loops.GraphicsPrimitive;
61 import sun.java2d.loops.XORComposite;
62 import sun.java2d.loops.Blit;
63 import sun.java2d.pipe.ValidatePipe;
64 import sun.java2d.pipe.PixelToShapeConverter;
65 import sun.java2d.pipe.TextPipe;
66 import sun.java2d.pipe.Region;
67
68 public abstract class X11SurfaceData extends XSurfaceData {
69 X11ComponentPeer peer;
70 X11GraphicsConfig graphicsConfig;
71 private RenderLoops solidloops;
72
73 protected int depth;
74
75 private static native void initIDs(Class<?> xorComp, boolean tryDGA);
76 protected native void initSurface(int depth, int width, int height,
77 long drawable);
78
79 public static final String
80 DESC_INT_BGR_X11 = "Integer BGR Pixmap";
81 public static final String
82 DESC_INT_RGB_X11 = "Integer RGB Pixmap";
83
84 public static final String
85 DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";
86 public static final String
87 DESC_INT_ARGB_PRE_X11 = "Integer ARGB Pixmap with pre-multiplied " +
88 "alpha";
89
90 public static final String
91 DESC_BYTE_IND_OPQ_X11 = "Byte Indexed Opaque Pixmap";
92
93 public static final String
94 DESC_INT_BGR_X11_BM = "Integer BGR Pixmap with 1-bit transp";
95 public static final String
191 SurfaceType.Custom.deriveSubType(DESC_USHORT_INDEXED_X11_BM);
192
193 public static final SurfaceType ByteIndexedX11_BM =
194 SurfaceType.Custom.deriveSubType(DESC_BYTE_IND_X11_BM);
195
196 public static final SurfaceType ByteGrayX11_BM =
197 SurfaceType.Custom.deriveSubType(DESC_BYTE_GRAY_X11_BM);
198 public static final SurfaceType Index8GrayX11_BM =
199 SurfaceType.Custom.deriveSubType(DESC_INDEX8_GRAY_X11_BM);
200
201
202 private static Boolean accelerationEnabled = null;
203
204 public Raster getRaster(int x, int y, int w, int h) {
205 throw new InternalError("not implemented yet");
206 }
207
208 protected X11Renderer x11pipe;
209 protected PixelToShapeConverter x11txpipe;
210 protected static TextPipe x11textpipe;
211 protected static boolean dgaAvailable;
212
213 static {
214 if (!isX11SurfaceDataInitialized() &&
215 !GraphicsEnvironment.isHeadless()) {
216 // If a screen magnifier is present, don't attempt to use DGA
217 String magPresent = java.security.AccessController.doPrivileged
218 (new sun.security.action.GetPropertyAction("javax.accessibility.screen_magnifier_present"));
219 boolean tryDGA = magPresent == null || !"true".equals(magPresent);
220
221 initIDs(XORComposite.class, tryDGA);
222
223 String xtextpipe = java.security.AccessController.doPrivileged
224 (new sun.security.action.GetPropertyAction("sun.java2d.xtextpipe"));
225 if (xtextpipe == null || "true".startsWith(xtextpipe)) {
226 if ("true".equals(xtextpipe)) {
227 // Only verbose if they use the full string "true"
228 System.out.println("using X11 text renderer");
229 }
230 x11textpipe = new X11TextRenderer();
231 if (GraphicsPrimitive.tracingEnabled()) {
232 x11textpipe = ((X11TextRenderer) x11textpipe).traceWrap();
233 }
234 } else {
235 if ("false".equals(xtextpipe)) {
236 // Only verbose if they use the full string "false"
237 System.out.println("using DGA text renderer");
238 }
239 x11textpipe = solidTextRenderer;
240 }
241
242 dgaAvailable = isDgaAvailable();
243
244 if (isAccelerationEnabled()) {
245 X11PMBlitLoops.register();
246 X11PMBlitBgLoops.register();
247 }
248 }
249 }
250
251 /**
252 * Returns true if we can use DGA on any of the screens
253 */
254 public static native boolean isDgaAvailable();
255
256 /**
257 * Returns true if shared memory pixmaps are available
258 */
259 private static native boolean isShmPMAvailable();
260
261 public static boolean isAccelerationEnabled() {
262 if (accelerationEnabled == null) {
263
264 if (GraphicsEnvironment.isHeadless()) {
265 accelerationEnabled = Boolean.FALSE;
266 } else {
267 String prop = java.security.AccessController.doPrivileged(
268 new sun.security.action.GetPropertyAction("sun.java2d.pmoffscreen"));
269 if (prop != null) {
270 // true iff prop==true, false otherwise
271 accelerationEnabled = Boolean.valueOf(prop);
272 } else {
273 boolean isDisplayLocal = false;
274 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
275 if (ge instanceof SunGraphicsEnvironment) {
276 isDisplayLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();
277 }
278
279 // EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.
280 // Don't use pixmaps if dga is available,
281 // or we are local and shared memory Pixmaps are not available.
282 accelerationEnabled =
283 !(isDgaAvailable() || (isDisplayLocal && !isShmPMAvailable()));
284 }
285 }
286 }
287 return accelerationEnabled.booleanValue();
288 }
289
290 @Override
291 public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
292 return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);
293 }
294
295 public void validatePipe(SunGraphics2D sg2d) {
296 if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&
297 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
298 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY ||
299 sg2d.compositeState == SunGraphics2D.COMP_XOR))
300 {
301 if (x11txpipe == null) {
302 /*
303 * Note: this is thread-safe since x11txpipe is the
|
55 import sun.java2d.SurfaceData;
56 import sun.java2d.SurfaceDataProxy;
57 import sun.java2d.loops.SurfaceType;
58 import sun.java2d.loops.CompositeType;
59 import sun.java2d.loops.RenderLoops;
60 import sun.java2d.loops.GraphicsPrimitive;
61 import sun.java2d.loops.XORComposite;
62 import sun.java2d.loops.Blit;
63 import sun.java2d.pipe.ValidatePipe;
64 import sun.java2d.pipe.PixelToShapeConverter;
65 import sun.java2d.pipe.TextPipe;
66 import sun.java2d.pipe.Region;
67
68 public abstract class X11SurfaceData extends XSurfaceData {
69 X11ComponentPeer peer;
70 X11GraphicsConfig graphicsConfig;
71 private RenderLoops solidloops;
72
73 protected int depth;
74
75 private static native void initIDs(Class<?> xorComp);
76 protected native void initSurface(int depth, int width, int height,
77 long drawable);
78
79 public static final String
80 DESC_INT_BGR_X11 = "Integer BGR Pixmap";
81 public static final String
82 DESC_INT_RGB_X11 = "Integer RGB Pixmap";
83
84 public static final String
85 DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";
86 public static final String
87 DESC_INT_ARGB_PRE_X11 = "Integer ARGB Pixmap with pre-multiplied " +
88 "alpha";
89
90 public static final String
91 DESC_BYTE_IND_OPQ_X11 = "Byte Indexed Opaque Pixmap";
92
93 public static final String
94 DESC_INT_BGR_X11_BM = "Integer BGR Pixmap with 1-bit transp";
95 public static final String
191 SurfaceType.Custom.deriveSubType(DESC_USHORT_INDEXED_X11_BM);
192
193 public static final SurfaceType ByteIndexedX11_BM =
194 SurfaceType.Custom.deriveSubType(DESC_BYTE_IND_X11_BM);
195
196 public static final SurfaceType ByteGrayX11_BM =
197 SurfaceType.Custom.deriveSubType(DESC_BYTE_GRAY_X11_BM);
198 public static final SurfaceType Index8GrayX11_BM =
199 SurfaceType.Custom.deriveSubType(DESC_INDEX8_GRAY_X11_BM);
200
201
202 private static Boolean accelerationEnabled = null;
203
204 public Raster getRaster(int x, int y, int w, int h) {
205 throw new InternalError("not implemented yet");
206 }
207
208 protected X11Renderer x11pipe;
209 protected PixelToShapeConverter x11txpipe;
210 protected static TextPipe x11textpipe;
211
212 static {
213 if (!isX11SurfaceDataInitialized() &&
214 !GraphicsEnvironment.isHeadless()) {
215
216 initIDs(XORComposite.class);
217
218 String xtextpipe = java.security.AccessController.doPrivileged
219 (new sun.security.action.GetPropertyAction("sun.java2d.xtextpipe"));
220 if (xtextpipe == null || "true".startsWith(xtextpipe)) {
221 if ("true".equals(xtextpipe)) {
222 // Only verbose if they use the full string "true"
223 System.out.println("using X11 text renderer");
224 }
225 x11textpipe = new X11TextRenderer();
226 if (GraphicsPrimitive.tracingEnabled()) {
227 x11textpipe = ((X11TextRenderer) x11textpipe).traceWrap();
228 }
229 } else {
230 if ("false".equals(xtextpipe)) {
231 // Only verbose if they use the full string "false"
232 System.out.println("using DGA text renderer");
233 }
234 x11textpipe = solidTextRenderer;
235 }
236
237 if (isAccelerationEnabled()) {
238 X11PMBlitLoops.register();
239 X11PMBlitBgLoops.register();
240 }
241 }
242 }
243
244 /**
245 * Returns true if shared memory pixmaps are available
246 */
247 private static native boolean isShmPMAvailable();
248
249 public static boolean isAccelerationEnabled() {
250 if (accelerationEnabled == null) {
251
252 if (GraphicsEnvironment.isHeadless()) {
253 accelerationEnabled = Boolean.FALSE;
254 } else {
255 String prop = java.security.AccessController.doPrivileged(
256 new sun.security.action.GetPropertyAction("sun.java2d.pmoffscreen"));
257 if (prop != null) {
258 // true iff prop==true, false otherwise
259 accelerationEnabled = Boolean.valueOf(prop);
260 } else {
261 boolean isDisplayLocal = false;
262 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
263 if (ge instanceof SunGraphicsEnvironment) {
264 isDisplayLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();
265 }
266
267 // EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.
268 // Don't use pixmaps if we are local and shared memory Pixmaps
269 // are not available.
270 accelerationEnabled = !(isDisplayLocal && !isShmPMAvailable());
271 }
272 }
273 }
274 return accelerationEnabled.booleanValue();
275 }
276
277 @Override
278 public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
279 return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);
280 }
281
282 public void validatePipe(SunGraphics2D sg2d) {
283 if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&
284 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
285 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY ||
286 sg2d.compositeState == SunGraphics2D.COMP_XOR))
287 {
288 if (x11txpipe == null) {
289 /*
290 * Note: this is thread-safe since x11txpipe is the
|