2007-03-23 02:04:48 +03:00
|
|
|
/* -*- 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.
|
|
|
|
*
|
2009-12-22 00:50:30 +03:00
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
2007-03-23 02:04:48 +03:00
|
|
|
* 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 "gfxContext.h"
|
|
|
|
#include "gfxFont.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
|
|
|
#include "gfxFontTest.h"
|
|
|
|
|
2007-04-02 23:06:16 +04:00
|
|
|
#if defined(XP_MACOSX)
|
2007-03-23 02:04:48 +03:00
|
|
|
#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;
|
|
|
|
|
2010-09-17 01:34:53 +04:00
|
|
|
surface = gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenSurface(gfxIntSize(size, size),
|
|
|
|
gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
|
2007-03-23 02:04:48 +03:00
|
|
|
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,
|
2009-01-29 23:39:18 +03:00
|
|
|
NS_FONT_STRETCH_NORMAL,
|
2007-03-23 02:04:48 +03:00
|
|
|
400,
|
|
|
|
16.0,
|
2010-03-08 18:45:00 +03:00
|
|
|
NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
|
2007-03-23 02:04:48 +03:00
|
|
|
0.0,
|
2010-07-14 00:31:31 +04:00
|
|
|
PR_FALSE, PR_FALSE, PR_FALSE,
|
|
|
|
NS_LITERAL_STRING(""),
|
|
|
|
NS_LITERAL_STRING(""));
|
2007-03-23 02:04:48 +03:00
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nsnull);
|
2007-03-23 02:04:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<gfxTextRun> textRun;
|
|
|
|
PRUint32 i;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isASCII = true;
|
2007-03-23 02:04:48 +03:00
|
|
|
for (i = 0; test->mString[i]; ++i) {
|
2007-03-30 01:48:46 +04:00
|
|
|
if (test->mString[i] & 0x80) {
|
2007-03-23 02:04:48 +03:00
|
|
|
isASCII = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gfxTextRunFactory::Parameters params = {
|
2007-05-09 02:46:14 +04:00
|
|
|
ctx, nsnull, nsnull, nsnull, 0, 60
|
2007-03-23 02:04:48 +03:00
|
|
|
};
|
2007-05-09 02:46:14 +04:00
|
|
|
PRUint32 flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
|
2007-03-23 02:04:48 +03:00
|
|
|
PRUint32 length;
|
|
|
|
if (isASCII) {
|
2007-05-09 02:46:14 +04:00
|
|
|
flags |= gfxTextRunFactory::TEXT_IS_ASCII |
|
|
|
|
gfxTextRunFactory::TEXT_IS_8BIT;
|
2007-03-23 02:04:48 +03:00
|
|
|
length = strlen(test->mString);
|
2007-07-08 11:08:04 +04:00
|
|
|
textRun = fontGroup->MakeTextRun(reinterpret_cast<const PRUint8*>(test->mString), length, ¶ms, flags);
|
2007-03-23 02:04:48 +03:00
|
|
|
} else {
|
|
|
|
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
|
|
|
|
length = str.Length();
|
2007-05-09 02:46:14 +04:00
|
|
|
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms, flags);
|
2007-03-23 02:04:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2007-03-30 01:48:46 +04:00
|
|
|
rv = gfxPlatform::Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return -1;
|
|
|
|
|
2007-03-23 02:04:48 +03:00
|
|
|
// 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;
|
2011-10-12 23:21:53 +04:00
|
|
|
test < NS_ARRAY_LENGTH(testList) - 1;
|
2007-03-23 02:04:48 +03:00
|
|
|
test++)
|
|
|
|
{
|
|
|
|
RunTest(&testList[test], context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntervalTime end = PR_IntervalNow();
|
|
|
|
|
|
|
|
printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
|
|
|
|
|
|
|
|
fflush (stderr);
|
|
|
|
fflush (stdout);
|
|
|
|
}
|