зеркало из https://github.com/mozilla/pjs.git
Bug 374830. gfxTextRun performance test harness. r=vlad
This commit is contained in:
Родитель
6c45cfc583
Коммит
676199d021
|
@ -54,6 +54,9 @@
|
||||||
#include "gfxQuartzSurface.h"
|
#include "gfxQuartzSurface.h"
|
||||||
#include "gfxQuartzFontCache.h"
|
#include "gfxQuartzFontCache.h"
|
||||||
|
|
||||||
|
// Uncomment this to dump all text runs created to stdout
|
||||||
|
// #define DUMP_TEXT_RUNS
|
||||||
|
|
||||||
#define ROUND(x) (floor((x) + 0.5))
|
#define ROUND(x) (floor((x) + 0.5))
|
||||||
|
|
||||||
/* We might still need this for fast-pathing, but we'll see */
|
/* We might still need this for fast-pathing, but we'll see */
|
||||||
|
@ -748,6 +751,12 @@ gfxAtsuiFontGroup::InitTextRun(gfxTextRun *aRun,
|
||||||
ATSUStyle mainStyle = atsuiFont->GetATSUStyle();
|
ATSUStyle mainStyle = atsuiFont->GetATSUStyle();
|
||||||
nsTArray<ATSUStyle> stylesToDispose;
|
nsTArray<ATSUStyle> stylesToDispose;
|
||||||
|
|
||||||
|
#ifdef DUMP_TEXT_RUNS
|
||||||
|
NS_ConvertUTF16toUTF8 str(aString + 1, aLength);
|
||||||
|
NS_ConvertUTF16toUTF8 families(mFamilies);
|
||||||
|
printf("%p(%s) TEXTRUN \"%s\" ENDTEXTRUN\n", this, families.get(), str.get());
|
||||||
|
#endif
|
||||||
|
|
||||||
UniCharCount runLengths = aLength;
|
UniCharCount runLengths = aLength;
|
||||||
ATSUTextLayout layout;
|
ATSUTextLayout layout;
|
||||||
// The string is actually aLength + 2*aHeaderChars chars, with optionally
|
// The string is actually aLength + 2*aHeaderChars chars, with optionally
|
||||||
|
|
|
@ -58,6 +58,7 @@ REQUIRES = \
|
||||||
CPPSRCS = \
|
CPPSRCS = \
|
||||||
gfxSurfaceRefCountTest.cpp \
|
gfxSurfaceRefCountTest.cpp \
|
||||||
gfxFontSelectionTest.cpp \
|
gfxFontSelectionTest.cpp \
|
||||||
|
gfxTextRunPerfTest.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Mozilla Corporation code.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is Mozilla Corporation.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsTArray.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsDependentString.h"
|
||||||
|
|
||||||
|
#include "prinrval.h"
|
||||||
|
|
||||||
|
#include "nsServiceManagerUtils.h"
|
||||||
|
#include "nsIPrefService.h"
|
||||||
|
#include "nsIPrefBranch.h"
|
||||||
|
|
||||||
|
#include "gfxContext.h"
|
||||||
|
#include "gfxFont.h"
|
||||||
|
#include "gfxPlatform.h"
|
||||||
|
|
||||||
|
#include "gfxFontTest.h"
|
||||||
|
|
||||||
|
#if defined(XP_WIN)
|
||||||
|
#include "gfxWindowsFonts.h"
|
||||||
|
#elif defined(MOZ_ENABLE_PANGO)
|
||||||
|
#include "gfxPangoFonts.h"
|
||||||
|
#elif defined(XP_MACOSX)
|
||||||
|
#include "gfxAtsuiFonts.h"
|
||||||
|
#include "gfxTestCocoaHelper.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MOZ_WIDGET_GTK2
|
||||||
|
#include "gtk/gtk.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct TestEntry {
|
||||||
|
const char* mFamilies;
|
||||||
|
const char* mString;
|
||||||
|
};
|
||||||
|
|
||||||
|
TestEntry testList[] = {
|
||||||
|
#include "per-word-runs.h"
|
||||||
|
{ nsnull, nsnull } // terminator
|
||||||
|
};
|
||||||
|
|
||||||
|
already_AddRefed<gfxContext>
|
||||||
|
MakeContext ()
|
||||||
|
{
|
||||||
|
const int size = 200;
|
||||||
|
|
||||||
|
nsRefPtr<gfxASurface> surface;
|
||||||
|
|
||||||
|
surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(size, size), gfxASurface::ImageFormatRGB24);
|
||||||
|
gfxContext *ctx = new gfxContext(surface);
|
||||||
|
NS_IF_ADDREF(ctx);
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsRefPtr<gfxFontGroup> fontGroup;
|
||||||
|
const char* lastFamilies = nsnull;
|
||||||
|
|
||||||
|
void
|
||||||
|
RunTest (TestEntry *test, gfxContext *ctx) {
|
||||||
|
if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
|
||||||
|
gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
|
||||||
|
FONT_VARIANT_NORMAL,
|
||||||
|
400,
|
||||||
|
FONT_DECORATION_NONE,
|
||||||
|
16.0,
|
||||||
|
nsDependentCString("x-western"),
|
||||||
|
0.0,
|
||||||
|
PR_FALSE, PR_FALSE);
|
||||||
|
|
||||||
|
#if defined(XP_WIN)
|
||||||
|
fontGroup = new gfxWindowsFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16);
|
||||||
|
#elif defined(MOZ_ENABLE_PANGO)
|
||||||
|
fontGroup = new gfxPangoFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16);
|
||||||
|
#elif defined(XP_MACOSX)
|
||||||
|
fontGroup = new gfxAtsuiFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoPtr<gfxTextRun> textRun;
|
||||||
|
PRUint32 i;
|
||||||
|
PRBool isASCII = PR_TRUE;
|
||||||
|
for (i = 0; test->mString[i]; ++i) {
|
||||||
|
if (test->mString[i] >= 0x80) {
|
||||||
|
isASCII = PR_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gfxTextRunFactory::Parameters params = {
|
||||||
|
ctx, nsnull, nsnull, nsnull, nsnull, 0, 60, 0
|
||||||
|
};
|
||||||
|
PRUint32 length;
|
||||||
|
if (isASCII) {
|
||||||
|
params.mFlags |= gfxTextRunFactory::TEXT_IS_ASCII |
|
||||||
|
gfxTextRunFactory::TEXT_IS_8BIT;
|
||||||
|
length = strlen(test->mString);
|
||||||
|
textRun = fontGroup->MakeTextRun(NS_REINTERPRET_CAST(const PRUint8*, test->mString), length, ¶ms);
|
||||||
|
} else {
|
||||||
|
params.mFlags |= gfxTextRunFactory::TEXT_HAS_SURROGATES; // just in case
|
||||||
|
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
|
||||||
|
length = str.Length();
|
||||||
|
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should we test drawing?
|
||||||
|
// textRun->Draw(ctx, gfxPoint(0,0), 0, length, nsnull, nsnull, nsnull);
|
||||||
|
|
||||||
|
textRun->GetAdvanceWidth(0, length, nsnull);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint32 iterations = 20;
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv) {
|
||||||
|
#ifdef MOZ_WIDGET_GTK2
|
||||||
|
gtk_init(&argc, &argv);
|
||||||
|
#endif
|
||||||
|
#ifdef XP_MACOSX
|
||||||
|
CocoaPoolInit();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialize XPCOM
|
||||||
|
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
// let's get all the xpcom goop out of the system
|
||||||
|
fflush (stderr);
|
||||||
|
fflush (stdout);
|
||||||
|
|
||||||
|
nsRefPtr<gfxContext> context = MakeContext();
|
||||||
|
|
||||||
|
// Start timing
|
||||||
|
PRIntervalTime start = PR_IntervalNow();
|
||||||
|
|
||||||
|
for (PRUint32 i = 0; i < iterations; ++i) {
|
||||||
|
for (uint test = 0;
|
||||||
|
test < NS_ARRAY_LENGTH(testList) - 1;
|
||||||
|
test++)
|
||||||
|
{
|
||||||
|
RunTest(&testList[test], context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PRIntervalTime end = PR_IntervalNow();
|
||||||
|
|
||||||
|
printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
|
||||||
|
|
||||||
|
fflush (stderr);
|
||||||
|
fflush (stdout);
|
||||||
|
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,169 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
# ***** BEGIN LICENSE BLOCK *****
|
||||||
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
#
|
||||||
|
# The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
# the License. You may obtain a copy of the License at
|
||||||
|
# http://www.mozilla.org/MPL/
|
||||||
|
#
|
||||||
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
# for the specific language governing rights and limitations under the
|
||||||
|
# License.
|
||||||
|
#
|
||||||
|
# The Original Code is Mozilla Corportation code.
|
||||||
|
#
|
||||||
|
# The Initial Developer of the Original Code is Mozilla Corporation.
|
||||||
|
# Portions created by the Initial Developer are Copyright (C) 2007
|
||||||
|
# the Initial Developer. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
# Robert O'Callahan <robert@ocallahan.org>
|
||||||
|
#
|
||||||
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
# of those above. If you wish to allow use of your version of this file only
|
||||||
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
# use your version of this file under the terms of the MPL, indicate your
|
||||||
|
# decision by deleting the provisions above and replace them with the notice
|
||||||
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
# the provisions above, a recipient may use your version of this file under
|
||||||
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
#
|
||||||
|
# ***** END LICENSE BLOCK *****
|
||||||
|
|
||||||
|
# This script is a bunch of utilities for computing statistics about the textruns
|
||||||
|
# created during a Gecko run.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# 1) Uncomment #define DUMP_TEXT_RUNS in gfxAtsuiFonts.cpp
|
||||||
|
# 2) Build
|
||||||
|
# 3) Run over some test set, redirecting stdout to a file
|
||||||
|
# 4) Pipe that file through this script
|
||||||
|
|
||||||
|
# --exclude-spaces-only: ignore all textruns that consistent of zero or more
|
||||||
|
# spaces
|
||||||
|
my $exclude_spaces = grep(/^--exclude-spaces-only$/, @ARGV);
|
||||||
|
|
||||||
|
# --dump-runs: process textruns into a format that can be used by
|
||||||
|
# gfxTextRunPerfTest, print that on standard output, and do nothing else
|
||||||
|
my $dump_runs = grep(/^--dump-runs$/, @ARGV);
|
||||||
|
|
||||||
|
# --obfuscate: ROTL13 the textrun text
|
||||||
|
my $obfuscate = grep(/^--obfuscate$/, @ARGV);
|
||||||
|
|
||||||
|
my @textruns = ();
|
||||||
|
|
||||||
|
while (<STDIN>) {
|
||||||
|
if (/^0x(\w+)\((.*)\) TEXTRUN "(.*)" ENDTEXTRUN$/) {
|
||||||
|
my %tr = ( fontgroup => $1,
|
||||||
|
families => $2,
|
||||||
|
text => $3 );
|
||||||
|
push(@textruns, \%tr);
|
||||||
|
} elsif (/^0x(\w+)\((.*)\) TEXTRUN "(.*)$/) {
|
||||||
|
my %tr = ( fontgroup => $1,
|
||||||
|
families => $2 );
|
||||||
|
my $text = $3."\n";
|
||||||
|
while (<STDIN>) {
|
||||||
|
if (/^(.*)" ENDTEXTRUN$/) {
|
||||||
|
$text .= $1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
$text .= $_;
|
||||||
|
}
|
||||||
|
$tr{text} = $text;
|
||||||
|
push(@textruns, \%tr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
my %quote = ( "\\" => 1, "\"" => 1 );
|
||||||
|
|
||||||
|
sub quote_str {
|
||||||
|
my ($text) = @_;
|
||||||
|
my @chars = split(//, $text);
|
||||||
|
my @strs = ();
|
||||||
|
foreach my $c (@chars) {
|
||||||
|
if (ord($c) >= 0x80) {
|
||||||
|
$c = "\\x".sprintf("%x",ord($c)).'""';
|
||||||
|
} elsif ($quote{$c}) {
|
||||||
|
$c = "\\$c";
|
||||||
|
} elsif ($c eq "\n") {
|
||||||
|
$c = " ";
|
||||||
|
}
|
||||||
|
push(@strs, $c);
|
||||||
|
}
|
||||||
|
return '"'.join("", @strs).'"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($dump_runs) {
|
||||||
|
foreach my $tr (@textruns) {
|
||||||
|
print "{ ", "e_str($tr->{families}), ",\n";
|
||||||
|
my $text = $tr->{text};
|
||||||
|
if ($obfuscate) {
|
||||||
|
$text =~ tr/a-mA-Mn-zN-Z/n-zN-Za-mA-M/;
|
||||||
|
}
|
||||||
|
print " ", "e_str($text), " },\n";
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
my %trs_by_text = ();
|
||||||
|
my %trs_by_text_and_fontgroup = ();
|
||||||
|
my %trs_by_trimmed_text_and_fontgroup = ();
|
||||||
|
my @tr_lengths = ();
|
||||||
|
|
||||||
|
$trs_by_text{" "} = [];
|
||||||
|
$trs_by_text{""} = [];
|
||||||
|
|
||||||
|
sub trim {
|
||||||
|
my ($s) = @_;
|
||||||
|
$s =~ s/^ *//g;
|
||||||
|
$s =~ s/ *$//g;
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $total_textruns = 0;
|
||||||
|
|
||||||
|
foreach my $tr (@textruns) {
|
||||||
|
if ($exclude_spaces && $tr->{text} =~ /^ *$/) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
++$total_textruns;
|
||||||
|
push(@{$trs_by_text{$tr->{text}}}, $tr);
|
||||||
|
push(@{$trs_by_text_and_fontgroup{$tr->{fontgroup}.$tr->{text}}}, $tr);
|
||||||
|
push(@{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup}.&trim($tr->{text})}}, $tr);
|
||||||
|
if (1 < scalar(@{$trs_by_trimmed_text_and_fontgroup{$tr->{fontgroup}.&trim($tr->{text})}})) {
|
||||||
|
$tr_lengths[length($tr->{text})]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Number of textruns:\t$total_textruns\n";
|
||||||
|
print "Number of textruns which are one space:\t", scalar(@{$trs_by_text{" "}}), "\n";
|
||||||
|
print "Number of textruns which are empty:\t", scalar(@{$trs_by_text{""}}), "\n";
|
||||||
|
|
||||||
|
my $count = 0;
|
||||||
|
foreach my $k (keys(%trs_by_text)) {
|
||||||
|
if ($k =~ /^ *$/) {
|
||||||
|
$count += @{$trs_by_text{$k}};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print "Number of textruns which are zero or more spaces:\t$count\n";
|
||||||
|
|
||||||
|
print "Number of unique textruns by text and fontgroup:\t", scalar(keys(%trs_by_text_and_fontgroup)), "\n";
|
||||||
|
print "Number of unique textruns by trimmed text and fontgroup:\t", scalar(keys(%trs_by_trimmed_text_and_fontgroup)), "\n";
|
||||||
|
|
||||||
|
my $sum = 0;
|
||||||
|
my $weighted_sum = 0;
|
||||||
|
if (1) {
|
||||||
|
print "Textrun length distribution:\n";
|
||||||
|
for my $i (0..(scalar(@tr_lengths)-1)) {
|
||||||
|
my $amount = defined($tr_lengths[$i])?$tr_lengths[$i]:0;
|
||||||
|
$sum += $amount;
|
||||||
|
$weighted_sum += $i*$amount;
|
||||||
|
print "$i\t$sum\t$weighted_sum\n";
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче