1 /* 2 * Copyright (c) 2011, 2015, 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 package com.sun.javafx.webkit.prism; 27 28 import com.sun.glass.ui.Screen; 29 import com.sun.javafx.geom.transform.BaseTransform; 30 import com.sun.media.jfxmedia.MediaManager; 31 import com.sun.prism.Graphics; 32 import com.sun.webkit.perf.WCFontPerfLogger; 33 import com.sun.webkit.perf.WCGraphicsPerfLogger; 34 import com.sun.webkit.graphics.*; 35 import java.io.IOException; 36 import java.io.InputStream; 37 import java.nio.ByteBuffer; 38 import java.nio.ByteOrder; 39 40 public final class PrismGraphicsManager extends WCGraphicsManager { 41 42 private final static float highestPixelScale; 43 private final static BaseTransform pixelScaleTransform; 44 45 static { 46 float ps = 1f; 47 for (Screen s : Screen.getScreens()) { 48 ps = Math.max(s.getRenderScale(), ps); 49 } 50 highestPixelScale = ps; 51 pixelScaleTransform = BaseTransform.getScaleInstance(ps, ps); 52 } 53 54 static BaseTransform getPixelScaleTransform() { 55 return pixelScaleTransform; 56 } 57 58 @Override public float getDevicePixelScale() { 59 return highestPixelScale; 60 } 61 62 @Override protected WCImageDecoder getImageDecoder() { 63 return new WCImageDecoderImpl(); 64 } 65 66 @Override public WCRenderQueue createRenderQueue(WCRectangle clip, 67 boolean opaque) 68 { 69 return new WCRenderQueueImpl(clip, opaque); 70 } 71 72 @Override protected WCRenderQueue createBufferedContextRQ(WCImage image) { 73 WCGraphicsContext g = new WCBufferedContext((PrismImage) image); 74 WCRenderQueue rq = new WCRenderQueueImpl( 75 WCGraphicsPerfLogger.isEnabled() 76 ? new WCGraphicsPerfLogger(g) : g); 77 image.setRQ(rq); 78 return rq; 79 } 80 81 @Override protected WCFont getWCFont(String name, boolean bold, boolean italic, float size) 82 { 83 WCFont f = WCFontImpl.getFont(name, bold, italic, size); 84 return WCFontPerfLogger.isEnabled() && (f != null) ? new WCFontPerfLogger(f) : f; 85 } 86 87 @Override 88 protected WCFontCustomPlatformData createFontCustomPlatformData( 89 InputStream inputStream) throws IOException 90 { 91 return new WCFontCustomPlatformDataImpl(inputStream); 92 } 93 94 @Override 95 public WCGraphicsContext createGraphicsContext(Object platG) { 96 WCGraphicsContext g = new WCGraphicsPrismContext((Graphics)platG); 97 return WCGraphicsPerfLogger.isEnabled() ? new WCGraphicsPerfLogger(g) : g; 98 } 99 100 @Override public WCPageBackBuffer createPageBackBuffer() { 101 return new WCPageBackBufferImpl(highestPixelScale); 102 } 103 104 @Override 105 protected WCPath createWCPath() { 106 return new WCPathImpl(); 107 } 108 109 @Override 110 protected WCPath createWCPath(WCPath path) { 111 return new WCPathImpl((WCPathImpl)path); 112 } 113 114 @Override 115 protected WCImage createWCImage(int w, int h) { 116 return new WCImageImpl(w, h); 117 } 118 119 @Override 120 protected WCImage createRTImage(int w, int h) { 121 return new RTImage(w, h, highestPixelScale); 122 } 123 124 @Override public WCImage getIconImage(String iconURL) { 125 return null; 126 } 127 128 @Override public Object toPlatformImage(WCImage image) { 129 return ((WCImageImpl) image).getImage(); 130 } 131 132 @Override 133 protected WCImageFrame createFrame(int w, int h, ByteBuffer bytes) { 134 int[] data = new int[bytes.capacity() / 4]; 135 bytes.order(ByteOrder.nativeOrder()); 136 bytes.asIntBuffer().get(data); 137 final WCImageImpl wimg = new WCImageImpl(data, w, h); 138 139 return new WCImageFrame() { 140 public WCImage getFrame() { return wimg; } 141 }; 142 } 143 144 @Override 145 protected WCTransform createTransform(double m00, double m10, double m01, 146 double m11, double m02, double m12) 147 { 148 return new WCTransform(m00, m10, m01, m11, m02, m12); 149 } 150 151 @Override 152 protected String[] getSupportedMediaTypes() { 153 String[] types = MediaManager.getSupportedContentTypes(); 154 // RT-19949: disable FLV support (workaround for youtube): 155 // if browser reports support for video/x-flv, youtube player sets 156 // media source to FLV (H264+AAC) stream and does not switch to MP4 on error 157 int len = types.length; 158 for (int i=0; i<len; i++) { 159 if ("video/x-flv".compareToIgnoreCase(types[i]) == 0) { 160 System.arraycopy(types, i+1, types, i, len-(i+1)); 161 len--; 162 } 163 } 164 if (len < types.length) { 165 String[] trimmedArray = new String[len]; 166 System.arraycopy(types, 0, trimmedArray, 0, len); 167 types = trimmedArray; 168 } 169 return types; 170 } 171 172 @Override 173 protected WCMediaPlayer createMediaPlayer() { 174 return new WCMediaPlayerImpl(); 175 } 176 }