2007-03-22 16:04:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 16:04:48 -07:00
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2007-03-22 16:04:48 -07:00
|
|
|
#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 12:06:16 -07:00
|
|
|
#if defined(XP_MACOSX)
|
2007-03-22 16:04:48 -07:00
|
|
|
#include "gfxTestCocoaHelper.h"
|
|
|
|
#endif
|
|
|
|
|
2012-06-27 17:15:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2007-03-22 16:04:48 -07:00
|
|
|
#include "gtk/gtk.h"
|
|
|
|
#endif
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 16:04:48 -07:00
|
|
|
struct TestEntry {
|
|
|
|
const char* mFamilies;
|
|
|
|
const char* mString;
|
|
|
|
};
|
|
|
|
|
|
|
|
TestEntry testList[] = {
|
|
|
|
#include "per-word-runs.h"
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nullptr, nullptr } // terminator
|
2007-03-22 16:04:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<gfxContext>
|
|
|
|
MakeContext ()
|
|
|
|
{
|
|
|
|
const int size = 200;
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surface;
|
|
|
|
|
2010-09-16 14:34:53 -07:00
|
|
|
surface = gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenSurface(gfxIntSize(size, size),
|
|
|
|
gfxASurface::ContentFromFormat(gfxASurface::ImageFormatRGB24));
|
2007-03-22 16:04:48 -07:00
|
|
|
gfxContext *ctx = new gfxContext(surface);
|
|
|
|
NS_IF_ADDREF(ctx);
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxFontGroup> fontGroup;
|
2012-07-30 07:20:58 -07:00
|
|
|
const char* lastFamilies = nullptr;
|
2007-03-22 16:04:48 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
RunTest (TestEntry *test, gfxContext *ctx) {
|
|
|
|
if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
|
|
|
|
gfxFontStyle style_western_normal_16 (FONT_STYLE_NORMAL,
|
2009-01-29 12:39:18 -08:00
|
|
|
NS_FONT_STRETCH_NORMAL,
|
2007-03-22 16:04:48 -07:00
|
|
|
400,
|
|
|
|
16.0,
|
2010-03-08 07:45:00 -08:00
|
|
|
NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
|
2007-03-22 16:04:48 -07:00
|
|
|
0.0,
|
2011-10-17 07:59:28 -07:00
|
|
|
false, false, false,
|
2010-07-13 13:31:31 -07:00
|
|
|
NS_LITERAL_STRING(""),
|
|
|
|
NS_LITERAL_STRING(""));
|
2007-03-22 16:04:48 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nullptr);
|
2007-03-22 16:04:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoPtr<gfxTextRun> textRun;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isASCII = true;
|
2007-03-22 16:04:48 -07:00
|
|
|
for (i = 0; test->mString[i]; ++i) {
|
2007-03-29 14:48:46 -07:00
|
|
|
if (test->mString[i] & 0x80) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isASCII = false;
|
2007-03-22 16:04:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
gfxTextRunFactory::Parameters params = {
|
2012-07-30 07:20:58 -07:00
|
|
|
ctx, nullptr, nullptr, nullptr, 0, 60
|
2007-03-22 16:04:48 -07:00
|
|
|
};
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
|
|
|
|
uint32_t length;
|
2007-03-22 16:04:48 -07:00
|
|
|
if (isASCII) {
|
2007-05-08 15:46:14 -07:00
|
|
|
flags |= gfxTextRunFactory::TEXT_IS_ASCII |
|
|
|
|
gfxTextRunFactory::TEXT_IS_8BIT;
|
2007-03-22 16:04:48 -07:00
|
|
|
length = strlen(test->mString);
|
2012-08-22 08:56:38 -07:00
|
|
|
textRun = fontGroup->MakeTextRun(reinterpret_cast<const uint8_t*>(test->mString), length, ¶ms, flags);
|
2007-03-22 16:04:48 -07:00
|
|
|
} else {
|
|
|
|
NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
|
|
|
|
length = str.Length();
|
2007-05-08 15:46:14 -07:00
|
|
|
textRun = fontGroup->MakeTextRun(str.get(), length, ¶ms, flags);
|
2007-03-22 16:04:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should we test drawing?
|
2012-07-30 07:20:58 -07:00
|
|
|
// textRun->Draw(ctx, gfxPoint(0,0), 0, length, nullptr, nullptr, nullptr);
|
2007-03-22 16:04:48 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
textRun->GetAdvanceWidth(0, length, nullptr);
|
2007-03-22 16:04:48 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t iterations = 20;
|
2007-03-22 16:04:48 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv) {
|
2012-06-27 17:15:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2007-03-22 16:04:48 -07:00
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
CocoaPoolInit();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initialize XPCOM
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = NS_InitXPCOM2(nullptr, nullptr, nullptr);
|
2007-03-22 16:04:48 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return -1;
|
|
|
|
|
2012-03-21 16:14:09 -07:00
|
|
|
if (!gfxPlatform::GetPlatform())
|
2007-03-29 14:48:46 -07:00
|
|
|
return -1;
|
|
|
|
|
2007-03-22 16:04:48 -07: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();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < iterations; ++i) {
|
2007-03-22 16:04:48 -07:00
|
|
|
for (uint test = 0;
|
2011-10-10 22:50:08 -07:00
|
|
|
test < ArrayLength(testList) - 1;
|
2007-03-22 16:04:48 -07:00
|
|
|
test++)
|
|
|
|
{
|
|
|
|
RunTest(&testList[test], context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntervalTime end = PR_IntervalNow();
|
|
|
|
|
|
|
|
printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
|
|
|
|
|
|
|
|
fflush (stderr);
|
|
|
|
fflush (stdout);
|
|
|
|
}
|