1 /*
   2  * Copyright (c) 2011, 2016, 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.webkit.perf;
  27 
  28 import com.sun.javafx.logging.PlatformLogger;
  29 import com.sun.webkit.graphics.WCFont;
  30 import com.sun.webkit.graphics.WCGlyphBuffer;
  31 
  32 public final class WCFontPerfLogger extends WCFont {
  33     private static final PlatformLogger log =
  34             PlatformLogger.getLogger(WCFontPerfLogger.class.getName());
  35 
  36     private static final PerfLogger logger = PerfLogger.getLogger(log);
  37 
  38     private final WCFont fnt;
  39 
  40     public WCFontPerfLogger(WCFont fnt) {
  41         this.fnt = fnt;
  42     }
  43 
  44     public synchronized static boolean isEnabled() {
  45         return logger.isEnabled();
  46     }
  47 
  48     public static void log() {
  49         logger.log();
  50     }
  51 
  52     public static void reset() {
  53         logger.reset();
  54     }
  55 
  56     public Object getPlatformFont() {
  57         return fnt.getPlatformFont();
  58     }
  59 
  60     public WCFont deriveFont(float size) {
  61         logger.resumeCount("DERIVEFONT");
  62         WCFont res = fnt.deriveFont(size);
  63         logger.suspendCount("DERIVEFONT");
  64         return res;
  65     }
  66 
  67     public int getOffsetForPosition(String str, float x) {
  68         logger.resumeCount("GETOFFSETFORPOSITION");
  69         int res = fnt.getOffsetForPosition(str, x);
  70         logger.suspendCount("GETOFFSETFORPOSITION");
  71         return res;
  72     }
  73 
  74     public WCGlyphBuffer getGlyphsAndAdvances(String str, int from, int to,
  75                                               boolean rtl) {
  76         logger.resumeCount("GETGLYPHSANDADVANCESFORCOMPLEXTEXT");
  77         WCGlyphBuffer adv = fnt.getGlyphsAndAdvances(str, from, to, rtl);
  78         logger.suspendCount("GETGLYPHSANDADVANCESFORCOMPLEXTEXT");
  79         return adv;
  80     }
  81 
  82     public int[] getGlyphCodes(char[] chars) {
  83         logger.resumeCount("GETGLYPHCODES");
  84         int[] res = fnt.getGlyphCodes(chars);
  85         logger.suspendCount("GETGLYPHCODES");
  86         return res;
  87     }
  88 
  89     public float getXHeight() {
  90         logger.resumeCount("GETXHEIGHT");
  91         float res = fnt.getXHeight();
  92         logger.suspendCount("GETXHEIGHT");
  93         return res;
  94     }
  95 
  96     public double getGlyphWidth(int glyph) {
  97         logger.resumeCount("GETGLYPHWIDTH");
  98         double res = fnt.getGlyphWidth(glyph);
  99         logger.suspendCount("GETGLYPHWIDTH");
 100         return res;
 101     }
 102 
 103     public double getStringWidth(String str) {
 104         logger.resumeCount("GETSTRINGLENGTH");
 105         double res = fnt.getStringWidth(str);
 106         logger.suspendCount("GETSTRINGLENGTH");
 107         return res;
 108     }
 109 
 110     public double[] getStringBounds(String str, int from, int to, boolean rtl) {
 111         logger.resumeCount("GETSTRINGBOUNDS");
 112         double[] res = fnt.getStringBounds(str, from, to, rtl);
 113         logger.suspendCount("GETSTRINGBOUNDS");
 114         return res;
 115     }
 116 
 117     public int hashCode() {
 118         logger.resumeCount("HASH");
 119         int res = fnt.hashCode();
 120         logger.suspendCount("HASH");
 121         return res;
 122     }
 123 
 124     public boolean equals(Object object) {
 125         logger.resumeCount("COMPARE");
 126         boolean res = fnt.equals(object);
 127         logger.suspendCount("COMPARE");
 128         return res;
 129     }
 130 
 131     public float getAscent() {
 132         logger.resumeCount("GETASCENT");
 133         float res = fnt.getAscent();
 134         logger.suspendCount("GETASCENT");
 135         return res;
 136     }
 137 
 138     public float getDescent() {
 139         logger.resumeCount("GETDESCENT");
 140         float res = fnt.getDescent();
 141         logger.suspendCount("GETDESCENT");
 142         return res;
 143     }
 144 
 145     public float getLineSpacing() {
 146         logger.resumeCount("GETLINESPACING");
 147         float res = fnt.getLineSpacing();
 148         logger.suspendCount("GETLINESPACING");
 149         return res;
 150     }
 151 
 152     public float getLineGap() {
 153         logger.resumeCount("GETLINEGAP");
 154         float res = fnt.getLineGap();
 155         logger.suspendCount("GETLINEGAP");
 156         return res;
 157     }
 158 
 159     public boolean hasUniformLineMetrics() {
 160         logger.resumeCount("HASUNIFORMLINEMETRICS");
 161         boolean res = fnt.hasUniformLineMetrics();
 162         logger.suspendCount("HASUNIFORMLINEMETRICS");
 163         return res;
 164     }
 165 
 166     public float getCapHeight() {
 167         logger.resumeCount("GETCAPHEIGHT");
 168         float res = fnt.getCapHeight();
 169         logger.suspendCount("GETCAPHEIGHT");
 170         return res;
 171     }
 172 }