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